2016-05-02 13 views

答えて

2

どのようにあなたはonchangeを使ってみてください。したがって、選択されたものに変更がない場合。何もトリガーされません。

0

ただ変更イベントを使用してください。ここに例があります:https://jsfiddle.net/rafb0vyw/2/

$('#sel').on('change', function() { 
    alert('change'); 
}) 
0

event.targetプロパティを確認することができますが、値は異なります。このように:

var select = document.querySelector('select'); 
 
var span = document.querySelector('span'); 
 

 
select.onclick = function(e) { 
 
    // show e.target in snippet (you would remove this line in your code): 
 
    span.textContent = 'You clicked on ' + e.target.tagName + '.' + 
 
     ' Current selected value is ' + select.value; 
 
    if(e.target.tagName !== 'SELECT') return; // ignore 
 
    // The rest of your event handling comes here... 
 
    // This will only be executed when you click the SELECT and not the OPTION. 
 
};
<select> 
 
    <option value = 'A'>Option A</option> 
 
    <option value = 'B'>Option B</option> 
 
</select> 
 
<span></span>

あなたのイベントハンドラ関数で定義されている(上記の例では電子という名前)イベントパラメータを持っていることを確認してください。

+0

私には役に立たない –

+0

それからすべてのブラウザがこれをサポートしているので、あなたは何か違うものがあると思います。スニペットを実行しましたか?をクリックすると、ドロップダウンの横にメッセージが表示されますか? – trincot

+0

私にはこのように動作します:selectをクリックしてsomethintを選択すると "select in click"と表示され、オプションを選択すると "option in click"と表示されます。 OPTIONタグの後ろにAまたはBがない場合。 –

関連する問題