如何通过conform验证后发送表单

<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窗口没有弹出呢?

阅读 1.5k
1 个回答

确认框是window.confirm,F12多看看console里的报错,可以帮助定位错位

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题