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");
}
}