admin管理员组文章数量:1297036
I've got a some trouble, i use
with this function
$('#email').on('keypress', function(event) {
$(this).mailcheck({
suggested: function(element, suggestion) {
$('#email_check').html("Did you mean <b><i><a href='#' id='suggest_email'>" + suggestion.full + "</a></b></i>?");
$('#suggest_email').on('click', function(event) {
event.preventDefault();
$('#email').val($(this).text());
$('#email_check').empty();
$('.error_js').empty()
});
},
empty: function(element) {
$('#email_check').empty();
$('.error_js').empty()
}
});
});
But when the script use :
opts.email = this.val();
(line 263 of this file .js )
this.val() return the old value of my input. i've tried to use a
this.attr("value");
and
this.prop("value");
Same problem.
When i do a console.log(this); and look for the value of my input, in the object, it's good, it contain the good value.
How to get the proper value then ? That's why i request your help.
Thanks.
I've got a some trouble, i use https://github./mailcheck/mailcheck
with this function
$('#email').on('keypress', function(event) {
$(this).mailcheck({
suggested: function(element, suggestion) {
$('#email_check').html("Did you mean <b><i><a href='#' id='suggest_email'>" + suggestion.full + "</a></b></i>?");
$('#suggest_email').on('click', function(event) {
event.preventDefault();
$('#email').val($(this).text());
$('#email_check').empty();
$('.error_js').empty()
});
},
empty: function(element) {
$('#email_check').empty();
$('.error_js').empty()
}
});
});
But when the script use :
opts.email = this.val();
(line 263 of this file https://github./mailcheck/mailcheck/blob/master/src/mailcheck.js )
this.val() return the old value of my input. i've tried to use a
this.attr("value");
and
this.prop("value");
Same problem.
When i do a console.log(this); and look for the value of my input, in the object, it's good, it contain the good value.
How to get the proper value then ? That's why i request your help.
Thanks.
Share Improve this question asked Jun 8, 2015 at 10:30 kaldorankaldoran 8556 silver badges19 bronze badges2 Answers
Reset to default 10Do not use the keypress
event because it is fired before the new value
or character
is registered in the input
. Use keyup instead
$('#email').on('keyup', function(event) {
$(this).mailcheck({
suggested: function(element, suggestion) {
$('#email_check').html("Did you mean <b><i><a href='#' id='suggest_email'>" + suggestion.full + "</a></b></i>?");
$('#suggest_email').on('click', function(event) {
event.preventDefault();
$('#email').val($(this).text());
$('#email_check').empty();
$('.error_js').empty()
});
},
empty: function(element) {
$('#email_check').empty();
$('.error_js').empty()
}
});
});
The console log object show the object properties at the time the object was first expanded, so in your case the value is not yet being set when the keypress event triggers, but when you read it later in the console, it's set. To see the actual current state of the object property, log that property only instead of the whole object.
The keyup event should work fine instead.
本文标签: javascriptJQueryval() return old valueStack Overflow
版权声明:本文标题:javascript - JQuery - .val() return old value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741640825a2389905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论