<form action="price.php" method="post">
<table>
<tr>
<td>商品</td>
<td><input type="text" name="goods"></td>
</tr>
<tr>
<td>价格</td>
<td><input type="text" name="price" id="price"></td>
</tr>
<tr><td colspan=2><input type="submit" id="submit" value="submit"></td></tr>
</table>
</form>
某些接收捐赠的商品,价格为零。
当输入了 input id=price中,输入了0的时候,跳出一个conform,点击"是",表单正式发送;点击“否”,表单不发送。
我写的js
ob = document.getElementById("submit");
function check(){
if(document.getElementById("price").value == 0){
var flag = window.conform(" are your sure price is 0 ?");
if(flag){
return true;
}else{
return false;
}
}
}
ob.addEventListener("click",check);
price.php
<?php
echo "price is " . $_POST["price"];
?>
为何表单中,price输入为零,conform窗口没有弹出呢?
确认框是
window.confirm
,F12多看看console里的报错,可以帮助定位错位