找出“模糊”的值是否与“模糊”的值不同;“焦点一”;(JavaScript+;jQuery)
我试图找出用户是否更改了文本字段或选择选项,如果是,那么做一些事情。我也在使用jQuery找出“模糊”的值是否与“模糊”的值不同;“焦点一”;(JavaScript+;jQuery),javascript,jquery,Javascript,Jquery,我试图找出用户是否更改了文本字段或选择选项,如果是,那么做一些事情。我也在使用jQuery $('.c').on('focus',function(){ var origval=this.value; $(this).on('blur',function(){ var newval=this.value; if(origval==newval){ alert('not changed'); }
$('.c').on('focus',function(){
var origval=this.value;
$(this).on('blur',function(){
var newval=this.value;
if(origval==newval){
alert('not changed');
}
else{
alert('changed');
}
});
});
但这不是正确的解决方案,我做错了什么。有时,它会提醒“已更改”,尽管它不应该这样做。谁能告诉我哪里出了毛病?多谢各位
由于在每个焦点上都会发生这种情况,因此模糊事件会被订阅多次 在订阅之前取消订阅模糊事件(关闭方法),或在发生模糊后取消订阅事件
$(this).off('blur').on('blur',function(){
模糊事件被订阅多次,因为这发生在每个焦点上 在订阅之前取消订阅模糊事件(关闭方法),或在发生模糊后取消订阅事件
$(this).off('blur').on('blur',function(){
模糊事件被订阅多次,因为这发生在每个焦点上 在订阅之前取消订阅模糊事件(关闭方法),或在发生模糊后取消订阅事件
$(this).off('blur').on('blur',function(){
模糊事件被订阅多次,因为这发生在每个焦点上 在订阅之前取消订阅模糊事件(关闭方法),或在发生模糊后取消订阅事件
$(this).off('blur').on('blur',function(){
您不必嵌套事件处理程序。它们可以是独立的,如下所示,当一个焦点出现时,值被保存,当另一个焦点出现时,进行比较
$(function() {
var formElement = $( '.c' );
formElement.on( 'focus', function() {
$( this ).data( 'focus', this.value );
});
formElement.on( 'blur', function() {
$( this ).data( 'blur', this.value );
if( $( this ).data( 'focus' ) === $( this ).data( 'blur' ) ) {
alert( this.nodeName +' not changed' );
} else {
alert( this.nodeName +' changed' );
}
});
});
不必嵌套事件处理程序。它们可以是独立的,如下所示,当一个焦点出现时,值被保存,当另一个焦点出现时,进行比较
$(function() {
var formElement = $( '.c' );
formElement.on( 'focus', function() {
$( this ).data( 'focus', this.value );
});
formElement.on( 'blur', function() {
$( this ).data( 'blur', this.value );
if( $( this ).data( 'focus' ) === $( this ).data( 'blur' ) ) {
alert( this.nodeName +' not changed' );
} else {
alert( this.nodeName +' changed' );
}
});
});
不必嵌套事件处理程序。它们可以是独立的,如下所示,当一个焦点出现时,值被保存,当另一个焦点出现时,进行比较
$(function() {
var formElement = $( '.c' );
formElement.on( 'focus', function() {
$( this ).data( 'focus', this.value );
});
formElement.on( 'blur', function() {
$( this ).data( 'blur', this.value );
if( $( this ).data( 'focus' ) === $( this ).data( 'blur' ) ) {
alert( this.nodeName +' not changed' );
} else {
alert( this.nodeName +' changed' );
}
});
});
不必嵌套事件处理程序。它们可以是独立的,如下所示,当一个焦点出现时,值被保存,当另一个焦点出现时,进行比较
$(function() {
var formElement = $( '.c' );
formElement.on( 'focus', function() {
$( this ).data( 'focus', this.value );
});
formElement.on( 'blur', function() {
$( this ).data( 'blur', this.value );
if( $( this ).data( 'focus' ) === $( this ).data( 'blur' ) ) {
alert( this.nodeName +' not changed' );
} else {
alert( this.nodeName +' changed' );
}
});
});
可能我的功能布局不好。不是吗?可能我的功能布局不好。不是吗?可能我的功能布局不好。不是吗?可能我的功能布局不好。是吗?+1我总是忘了你可以这样叫内联。+1我总是忘了你可以那样叫内联。+1我总是忘了你可以那样叫内联。+1我总是忘了你可以那样叫内联。非常感谢你的建议!非常感谢您的建议!非常感谢您的建议!非常感谢您的建议!