所以我之前问过这个问题并得到了答案,但仍然不起作用,我稍微改变了代码,基本上我想根据正在运行的函数选择一个 onchange() 事件。所以我有下面的代码,但它没有做任何事情,下面的 onchange 将触发 checkVal() 函数,在这个函数中我想说,如果某个函数在页面上运行,例如。 updatebrand() 然后运行 onchange event updatestyle(),我知道我这样做不对:
<SELECT NAME="choicestyle" onChange="checkVal()"; >
<option disabled="disabled" selected="selected"></option>
<SCRIPT>
function checkVal(){
var e = document.getElementById("choicestyle");
e.onchange = function() {
if (e.value == "updatebrand()") {
updatestyle();
} else if (e.value == "updatenewbrand") {
updatenewstyle();
}
}
}
</SCRIPT>
所以我现在用这段代码编辑了顶部代码,它给出了一个错误,我将 $lastRunFunc 放入两个函数 updateBrand() 中,并将其设置为 0 并将其放入 updatenewBrand() 并将其设置为1,所以当 onchange 发生时,它应该触发 updatestyle() 和 updatenewstyle() 函数,但我不断收到对象预期错误?
<SELECT NAME="choicestyle" onChange="checkVal();">
<option disabled="disabled" selected="selected"></option>
<?
echo "checkVal() {\n\n";
if($lastRunFunc==0)
{
echo "updatestyle();\n";
}
if($lastRunFunc==1)
{
echo "updatenewstyle();\n";
}
echo "}\n\n";
?>
最佳答案
Note: Its really bad practice to use capitals in HTML and inline javascript. That is why I converted to
addEventListener()
calls.
关于javascript - 根据功能选择特定的 onchange 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20547159/