我在Div中有5个textbox,div和textbox是使用jquery动态创建的,如果textbox有值或空,则需要验证textbox,如果div中的一个textbox为null,则错误消息将在span中显示,SPAN标记也位于div中。文本框在为空时也会变红,该部分可以工作,但是消息错误有问题。有什么想法吗?
这是HTML
<div id="QuestionTBDiv1" >
<label>Question</label><br/>
<input type="text" name="quiztxtBox[]" size="57" id="quiztxtBox[]" placeholder="Question #1"><br/>
<label>Answer</label><br/>
<input type="text" name="quiztxtBox[]" size="24" id="answer[]" placeholder="Choice A"> <input type="radio" class = "choiceA" name="correct_answer1" value="A"> <input type="text" name="quiztxtBox[]" size="24" id="answer[]" placeholder="Choice B"> <input type="radio" class = "choiceB" name="correct_answer1" value="B"><br/><input type="text" name="quiztxtBox[]" size="24" id="answer[]" placeholder="Choice C"> <input type="radio" class = "choiceC" name="correct_answer1" value="C"> <input type="text" name="quiztxtBox[]" size="24" id="answer[]" placeholder="Choice D"> <input type="radio" class = "choiceD" name="correct_answer1" value="D"><br><span name="errMchoice" class="errorMsg"></span>
</div> 这是JQUERY
$("[name='quiztxtBox[]']").each(function(){
if ($(this).empty()) {
$(this).css({"background-color":"#f6d9d4"});
$( "div span:last-child" ).html("This is error message.");
}
});发布于 2014-02-04 01:59:43
$( "div :末后子“).html(”这是错误消息。“);
我想这应该是
$( "div span" ).text("This is error message.");
或
$( "div:last-child" ).text("This is error message.");
因为span是div的最后一个子元素,也是div旁边唯一的span元素。而且,.text,因为您设置的值不是HTML,而是文本内容。希望这能有所帮助!
https://stackoverflow.com/questions/21541511
复制相似问题