【发布时间】:2013-12-12 15:12:38
【问题描述】:
所以我之前问过这个问题并得到了答案但仍然无法正常工作,我稍微更改了代码,基本上我想根据正在运行的函数选择一个 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 放在 2 个函数 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";
?>
【问题讨论】:
标签: javascript html function triggers onchange