本文介绍了获取跨度的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到span的内容?
我正在寻找一种方式,所有这一切都是香草,而不是jQuery



javascript(和一个小jQuery)

  var swear_words_arr = new Array(bad,evil,freak); 
var regex = new RegExp('\\b('+ swear_words_arr.join('|')+')\\'','i');

函数validate_user_text(){
var text = document.getElementById('myInput');
text.text();

if(regex.test(text)){
window.location =http://www.newlocation.com;
返回false;
}


var myVar = setInterval(function(){validate_user_text()},1000); change

这是我的html

 < div id =textArea > 
< span id =myInputcontenteditable =true> kfjdkfj< / span>
< / div>
< br />
< form name =form1method =postaction =>

< br />
< input type =buttonvalue =Submitonclick =return validate_user_text();>< / form>

谢谢

解决方案 $ p
$ b

  var input = document.getElementById(myInput); 
var text = input.innerHTML;


how can I get the contents of span ?I'm looking for a way for all of this to be vanilla, not jQuery

javascript (and a little jQuery)

var swear_words_arr=new Array("bad","evil","freak");
var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );

function validate_user_text() {
var text = document.getElementById('myInput');
text.text();

if(regex.test(text)) {
    window.location="http://www.newlocation.com";
    return false;
}

}
var myVar=setInterval(function(){validate_user_text()},1000);change

here's my html

<div id="textArea">
<span id="myInput" contenteditable="true">kfjdkfj</span>
</div>
<br />
 <form name="form1" method="post" action="">

<textarea rows="3" cols="40" name="user_text" style="border:2 solid #808080; font-family:verdana,arial,helvetica; font-weight:normal; font-size:10pt" onclick="select_area()"></textarea>
<br />
<input type="button" value="Submit" onclick="return validate_user_text();"></form>

Thank You

解决方案

Give this a shot:

var input = document.getElementById("myInput");
var text = input.innerHTML;

这篇关于获取跨度的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 19:34