Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 空字段检查_Javascript - Fatal编程技术网

Javascript 空字段检查

Javascript 空字段检查,javascript,Javascript,我的流动代码工作正常,但我需要检查是否有空字段,如果字段为空,则显示消息并不转到新页面。我一直试图添加代码,但它崩溃的帮助 发现 <script> function gotoURL(){ var newURL = document.GotoForm.theURL.value document.location.href="http://www.bluediamond.tv/jobs/" + newURL } </script&g

我的流动代码工作正常,但我需要检查是否有空字段,如果字段为空,则显示消息并转到新页面。我一直试图添加代码,但它崩溃的帮助

发现

<script>
    function gotoURL(){
        var newURL = document.GotoForm.theURL.value
        document.location.href="http://www.bluediamond.tv/jobs/" + newURL
    }
</script>

</head>

<body>
    <form action="JavaScript:gotoURL()" method="GET" name="GotoForm">
        <p align="center"><input maxlength="100" name="theURL" size="20" type=“find” value="" align="middle" /></p>
        <p align="center"><input type="submit" value="View Photographs" /></p>
    </form> 
</body>

函数gotour(){
var newURL=document.GotoForm.theURL.value
document.location.href=”http://www.bluediamond.tv/jobs/“+newURL
}


好的,首先把它添加到输入的标记中

class="myInput"
然后更新你的函数

function gotoURL(){
        if($('.myInput').val() == ""){
                alert('please fill this field');
        }else{
                var newURL = $('.myInput').val();
                document.location.href="http://www.bluediamond.tv/jobs/" + newURL;
        }
}
试试下面

function gotoURL(){
  var newURL = document.GotoForm.theURL.value;
  if(newURL && newURL.trim()) {
    document.location.href="http://www.bluediamond.tv/jobs/" + newURL.trim();
  } else {
    alert("Please fill the URL");
  }
}