我有这个javascript函数,
function listQ(){
var e = document.getElementById("list");
if(e.selectedIndex > 0){
if("Blank Test" === e.selectedIndex){ alert("yo"); }
}
}
My problem is how to trigger the function when selected the same value of dropdown list?
我试过这段代码,
document.getElementById("list").addEventListener("change",listQ);
而且它必须使用事件侦听器。
原文由 John Arellano 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以在选择元素上使用
onchange
方法。对于这个 HTML
Here is a Fiddle fork from Jonathan ,这里是 mdn documentation for the change event。