JS问题汇总

JS问题汇总

1.函数无法调用

报错:Uncaught TypeError: cannel is not a function
onclick http://localhost:63342/JS/reg.html?_ijt=813qjshvttc2upu0fj9i4pvsq8:1

<tr>
 <td colspan="8" align="center">
  <input type="button" name="reg" value="提交" onclick="reg()">
  <input type="button" name="cannel" value="取消" onclick="cannel()">
 </td>
</tr>
<script>
    function reg() {
        alert(1);
        if (document.frm.zw.value == "") {
            alert("请输入职位");
        } else if (document.frm.zc.value == "") {
            alert("请输入职称");
        } else if (document.frm.gh.value == "") {
            alert("请输入工号");
        } else if (document.frm.name.value == "") {
            alert("请输入姓名");
        } else if (document.frm.birth.value == "") {
            alert("请输入生日")
        } else if (!checkbirth()) {
            alert("出生日期格式错误")
        } else if (document.frm.address.value == "") {
            alert("请输入地址");
        } else if (document.frm.zip.value == "") {
            alert("请输入邮编");
        } else if (document.frm.phone.value == "") {
            alert("请输入电话号码");
        } else if (document.frm.pass.value == "") {
            alert("请输入密码");
        } else if (document.frm.confirm_pass.value == "") {
            alert("请输入确认密码");
        } else if (checkpass()) ;
    }

    function checkbirth() {
        birth = document.frm.birth.value;
        if (isNaN(birth.substr(0, 4))) {
            return false;
        } else if (birth.substr(4, 1) != "-") {
            return false;
        }
        if (isNaN(birth.substr(5, 2))) {
            return false;
        } else if (birth.substr(7, 1) != "-") {
            return false;
        } else if (isNaN(birth.substr(8, 2))) {
            return false;
        }
    }

    function checkpass() {
        pass = document.frm.pass;
        confirm_pass = document.frm.confirm_pass;
        if (pass == confirm_pass) {
            return true;
        } else {
            alert("两次密码不同");
        }
    }

    function cannel() {
        console.debug("cannel")
    }
    
</script>

原因:onclick方法执行的函数名称与控件名相同

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值