【发布时间】:2017-09-13 04:55:23
【问题描述】:
我需要检查点击事件中的空输入,如果为空则停止脚本。发生的事情是脚本仍在发布到 php 脚本并且完全忽略了我的代码。我使用了 if 语句进行检查,但显然它是不正确的。我可能需要其他?
如果有人能指出我的错误,我将不胜感激。谢谢
<script type="text/javascript">
$(function () {
$('#srcRslt').click(function (e) {
e.preventDefault();
if ($('#srcBoxRslt').length == 0) { <--- This the problem area
notif({
type: "error",
msg: "<b>ERROR:<br /><br />You must enter a box to destroy</b>",
height: 99,
multiline: true,
position: "middle,center",
fade: true,
timeout: 3000
});
return false;
}
var value = $('#srcBoxRslt').val();
//alert(value);
var qString = 'sub=' + value;
//alert(qString);
$.post('bdSrchadmin.php', qString, processResponse);
});
function processResponse(data) {
//$('#resultsGoHere').html(data);
//$('#boxdest').empty();
//$("#boxdest").append("<option value='" + data + "'>" + data + "</option>");
// $('#srcBoxRslt').val(data);
$("#submit").prop("disabled", false);
$("#submit2").prop("disabled", false);
$("#submit3").prop("disabled", false);
$('#srcBoxRslt').val('');
$('#srcBox').val('');
notif({
type: "error",
msg: "<b>SUCCESS:<br /><br />You have destroyed boxes.</b>" + data,
height: 99,
multiline: true,
position: "middle,center",
fade: true,
timeout: 3000
});
$("#boxdest").load("bdrefreshBox.php");
};
//$('#boxdest').append('<option value="'.data.'" selected="selected">data</option>');
//$('#boxdest').append(data);
//alert(data);
});
</script>
【问题讨论】:
-
$('#srcBoxRslt').length返回#srcBoxRslt选择的元素数量(可能是1)。另外,请使用搜索。
标签: javascript jquery