admin管理员组文章数量:1305212
I've got a jQuery validation function that adds classes and changes some informational text on blur. The .addClass and .removeClass methods are working fine but .text does not. I have a feeling that I'm missing something simple and fundamental but my poor JavaScript knowledge might be a hindrance. Thanks to anyone who can help!
$(document).ready(function(){
$('.required-text').on('blur', function() {
$(this).removeClass('error');
if($.trim(this.value).length < 1) {
$(this).addClass('error');
var fieldText = "#" + this.id + "_info";
$(fieldText).removeClass('forminfo');
$(fieldText).addClass('forminfo_error');
$(fieldText).text = "This field is required.";
}
}
});
<input type="text" name="first_name" id="first_name" value="" class="form-text required-text">
<span id="first_name_info" class="forminfo">Required</span>
I've got a jQuery validation function that adds classes and changes some informational text on blur. The .addClass and .removeClass methods are working fine but .text does not. I have a feeling that I'm missing something simple and fundamental but my poor JavaScript knowledge might be a hindrance. Thanks to anyone who can help!
$(document).ready(function(){
$('.required-text').on('blur', function() {
$(this).removeClass('error');
if($.trim(this.value).length < 1) {
$(this).addClass('error');
var fieldText = "#" + this.id + "_info";
$(fieldText).removeClass('forminfo');
$(fieldText).addClass('forminfo_error');
$(fieldText).text = "This field is required.";
}
}
});
<input type="text" name="first_name" id="first_name" value="" class="form-text required-text">
<span id="first_name_info" class="forminfo">Required</span>
Share
Improve this question
asked Apr 16, 2012 at 15:59
Sean CunninghamSean Cunningham
3,1165 gold badges26 silver badges37 bronze badges
2 Answers
Reset to default 7try $(fieldText).text("This field is required.");
instead
see documentation about text()
: http://api.jquery./text/
$(fieldText).removeClass('forminfo').addClass('forminfo_error').text("This field is required.");
本文标签: javascriptjQuery text not workingStack Overflow
版权声明:本文标题:javascript - jQuery .text not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741735470a2395039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论