我的流动代码工作正常但是我需要检查空字段,如果字段为空显示消息,不则转到新页面。我一直试图将代码添加到它但它崩溃了HELP
查找
<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>
答案 0 :(得分:1)
好的,首先在输入标记
中添加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;
}
}
答案 1 :(得分:0)
尝试以下...
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");
}
}