<select onchange="alert();">
<option>d</option>
<option>de</option>
<option>dewe</option>
<option>dewee</option>
</select>
を選択れるonchange私は警告を表示する<select>
要素ののonchangeイベントをしたいが、それは働いていません。が実行機能
何か問題がありますか?
<select onchange="alert();">
<option>d</option>
<option>de</option>
<option>dewe</option>
<option>dewee</option>
</select>
を選択れるonchange私は警告を表示する<select>
要素ののonchangeイベントをしたいが、それは働いていません。が実行機能
何か問題がありますか?
しかし、あなたはまた、あなたがjQuery
$(function(){
$("select").change(function(){
alert($(this).val());
});
});
+1 jQueryを提案するために、それを含めることを忘れないでください! –
を含めて、これを試すことができます私はあなたの問題がalert()
呼び出しが未定義代わりの<select>
の値を表示することであると仮定しています。
あなたが<select>
の値を表示したい場合は、代わりに次の操作を行います。
<select onchange="alert(this.value);">
<option>d</option>
<option>de</option>
<option>dewe</option>
<option>dewee</option>
</select>
それとも、あなたが実際にjQueryを使用している場合、あなたはこのようにそれを行うことができました:
//This is an anonymous function that calls itself with the jQuery object as an argument
//This allows you to use the `$` when making jQuery calls but the code
//will run without modification if jQuery is in noConflict() mode
(function($) {
//This is the important part
//Here, we bind to the change event and alert the value
$('select').change(function(e) {
alert($(this).val());
});
})(jQuery)
アラート機能では、文字列をパラメータとして指定する必要があります。
これは機能します。 – bfavaretto
それは:http://jsfiddle.net/H4kuk/です。 – pimvdb
[作品](http://jsfiddle.net/cggdc/)私にとっては.. – Prisoner