選択がプログラムによって変更されるたびに、HTML select 要素に関数を呼び出させる方法はありますか?
IE と FF はどちらも、選択ボックス内の現在の選択が JavaScript で変更された場合に「onchange」を起動しません。さらに、選択を変更するjs関数はフレームワークの一部であるため、たとえば最後に onchange() をトリガーするように変更することはできません。
次に例を示します。
<body>
<p>
<select id="sel1" onchange="myfunction();"><option value="v1">n1</option></select>
<input type="button" onclick="test();" value="Add an option and select it." />
</p>
<script type="text/javascript">
var inc = 1;
var sel = document.getElementById('sel1');
function test() {
inc++;
var o = new Option('n'+inc, inc);
sel.options[sel.options.length] = o;
o.selected = true;
sel.selectedIndex = sel.options.length - 1;
}
function myfunction() {
document.title += '[CHANGED]';
}
</script>
</body>
test() を変更せずに (またはボタンにイベントを追加せずに)、test() に myfunction() を呼び出させる方法はありますか?
ありがとう。