2016-10-14 13 views
1

このイベントはなぜ2回発生しますか?jqWidgetsでイベントが2回発生する

回避策はevent.argsを確認することですが、イベントはまだ2回発生します。

$('#input').jqxInput({ 
 
    width: 200, 
 
    height: 25 
 
}); 
 

 
var changedCount = 0; 
 
$('#input').on('change', function(event) { 
 
    console.log("changed"); 
 
    console.log(event.args != undefined) 
 
    changedCount++; 
 
    $("#log").html("total times fired: " + changedCount); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="http://jqwidgets.com/public/jqwidgets/styles/jqx.base.css" rel="stylesheet" /> 
 
<script src="http://jqwidgets.com/public/jqwidgets/jqx-all.js"></script> 
 

 
<input id="input"> 
 
<div id='log'></div>

答えて

0

Jsfiddle

代わりの変更ぼかしを試しにこれを試してみてください。

var changedCount = 0; 
$('#input').on('blur', function(event) { 
    console.log("changed"); 
    console.log(event.args != undefined) 
    changedCount++; 
    $("#log").html("total times fired: " + changedCount); 
}); 
+0

これは悪くないが、ユーザーが入力フィールドを離れるたびにイベントが発生するようになりました。 –

+0

@MattJacobsen私はjsfiddleを更新しました。ユーザーが何らかの値を入力したまま放置すると、これが起動します。 –

0

次のことを試してみてください。

$('#input').on('change', function(event) { 
    if (!event.args) return; 

    console.log("changed"); 
    console.log(event.args != undefined) 
    changedCount++; 
    $("#log").html("total times fired: " + changedCount); 
}); 

あなたはINPUTタグの標準Javascriptの変更イベント、jQWidgetsカスタムイベントが発生していることを確認していないことを行います。

関連する問題