我碰到过很多次(我不想在这里使用'输入类型按钮')为什么哦'onclick'为什么没有不调用函数check(); ?即使字段为空,页面仍然会提交。谢谢您的意见。'onclick'似乎没有用'submit'按钮调用函数
的Javascript:
function check() {
var name = document.getElementById('username_res');
var passw_old = document.getElementById('passw_reset_old');
var passw_new = document.getElementById('passw_reset');
var button_res = document.getElementById('sub_res');
if ((name.val() == "") && (passw_old.val().length == "") && (passw_new.val().length == "")) {
button_res.disabled = true;
} else {
button_res.disabled = false;
}
}
HTML:
<form id="passw_res" name="passw_res" method="post" action="pass_reset.php">
<fieldset style="width:300px"><br/>
<legend id="pass_legend" align="left">Password reset</legend><br/>
<input type="text" id="username_res" name="username_res" maxlength="50" />
<input type="password" id="passw_reset_old" name="passw_reset_old" maxlength="16"/>
<input type="password" id="passw_reset" name="passw_reset" maxlength="16" />
<input type="submit" value="submit" id="sub_res" name="sub_res" onclick="check();"/>
</fieldset>
</form>
所以...页面不应该空字段提交 - 为什么它提交?谢谢..
你不能使用'onsubmit'事件的原因吗? – FishBasketGordo
使用'onsubmit'。并在函数中返回false;以防止在必要时提交。 –