Javascript 如何将函数应用于按钮
我有4个下拉列表。每个下拉列表都有所有假值和一个真值,我的目标是生成一条警告消息,并根据这些值打开一个新页面。但是,我想知道如何将此代码应用于按钮,以便在单击按钮时发生所描述的操作,因为此时绝对没有发生任何事情Javascript 如何将函数应用于按钮,javascript,javascript-events,Javascript,Javascript Events,我有4个下拉列表。每个下拉列表都有所有假值和一个真值,我的目标是生成一条警告消息,并根据这些值打开一个新页面。但是,我想知道如何将此代码应用于按钮,以便在单击按钮时发生所描述的操作,因为此时绝对没有发生任何事情 <input name="button" type="submit" class="main" id="button" value="Submit" onclick="submit()" /> </script> <script type="javas
<input name="button" type="submit" class="main" id="button" value="Submit" onclick="submit()" />
</script>
<script type="javascript">
这是我的按钮的详细信息,放在这里供您参考
<input name="button" type="submit" class="main" id="button" value="Submit" onclick="submit()" />
var selectbox = document.getElementById("select_box");
var a = selectbox.options[selectbox.selectedIndex].value;
var selectbox2 = document.getElementById("select_box2");
var b = selectbox2.options[selectbox2.selectedIndex].value;
var selectbox3 = document.getElementById("select_box3");
var c = selectbox3.options[selectbox3.selectedIndex].value;
var selectbox4 = document.getElementById("select_box4");
var d = selectbox4.options[selectbox4.selectedIndex].value;
if (a == "true" && b == "true" && c == "true" && d == "true")
{
alert("Correct you have won press OK for your Reward!")
document.open("Reward.html");
}
else
{
alert("Not right Please try again!");
}
</script>
var selectbox=document.getElementById(“选择框”);
变量a=selectbox.options[selectbox.selectedIndex].value;
var selectbox2=document.getElementById(“select_box2”);
var b=selectbox2.options[selectbox2.selectedIndex].value;
var selectbox3=document.getElementById(“select_box3”);
var c=selectbox3.options[selectbox3.selectedIndex].value;
var selectbox4=document.getElementById(“select_box4”);
var d=selectbox4.options[selectbox4.selectedIndex].value;
如果(a==“真”&&b==“真”&&c==“真”&&d==“真”)
{
警告(“更正您已赢,请按“确定”以获得奖励!”)
document.open(“Reward.html”);
}
其他的
{
警告(“不对,请再试一次!”);
}
确保onClick值指向如下函数:
<input name="button" type="submit" class="main" id="button" value="Submit" onclick="checkValues();"/>
祝你好运 即使单击按钮,我仍然没有得到任何信息,按钮的代码是否需要实际位于所有if语句所在的位置或其他位置?请尝试添加一些alert()语句以查看问题所在。函数是否实际被调用?selectbox变量是否有值?还要确保检查JavaScript的错误日志,以获取一些指向错误的指针。
function checkValues(){
var selectbox = document.getElementById("select_box");
var a = selectbox.options[selectbox.selectedIndex].value;
var selectbox2 = document.getElementById("select_box2");
var b = selectbox2.options[selectbox2.selectedIndex].value;
var selectbox3 = document.getElementById("select_box3");
var c = selectbox3.options[selectbox3.selectedIndex].value;
var selectbox4 = document.getElementById("select_box4");
var d = selectbox4.options[selectbox4.selectedIndex].value;
if (a == "true" && b == "true" && c == "true" && d == "true")
{
alert("Correct you have won press OK for your Reward!")
document.open("Reward.html");
}
else
{
alert("Not right Please try again!");
}
}