小编Chr*_*unt的帖子

返回true或false不能在JavaScript中工作

我的返回值不起作用,我需要它们才能工作,所以我可以验证页面.我在函数中有一个函数,因为会编写更多的代码,需要这种设置.

这是JavaScript代码:

var postalconfig = /^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/;

function outer(){
    function checkpostal(postal_code){
      if (postalconfig.test(document.myform.postal_code.value)) {
        alert("VALID SSN");
        return true;
      } else {
        alert("INVALID SSN");
        return false;
      }
    }
  checkpostal();
}
Run Code Online (Sandbox Code Playgroud)

和HTML:

<form name="myform" action="index.php" onSubmit="return outer();" method="post">
    Postal Code <input name="postal_code"  type="text" />
    <input name="Submit" type="submit"  value="Submit Form" >
</form>
Run Code Online (Sandbox Code Playgroud)

html javascript forms return-value

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

forms ×1

html ×1

javascript ×1

return-value ×1