如何为此进行“检查”以检查文本字段是否为空?
查询:
$("#AddGoogleMap").click(function () {
if($('#googleMapCity').val()==null) {
alert("You need to fill out a city");
} else {
// do something
}
如何为此进行“检查”以检查文本字段是否为空?
查询:
$("#AddGoogleMap").click(function () {
if($('#googleMapCity').val()==null) {
alert("You need to fill out a city");
} else {
// do something
}
首先,删除字符串开头和结尾的空格,然后将值与空字符串进行比较,例如:
if( $.trim($('#googleMapCity').val()) === '') {
alert("You need to fill out a city");
} else {
// do something
}
if($('#googleMapCity').val() === "") {
alert("You need to fill out a city");
}
可以这样做:
if($.trim($('#googleMapCity').val())==="")
$("#AddGoogleMap").click(function () {
if($('#googleMapCity').val()==='') {
alert('You need to fill out a city');
} else {
// do something
}
$("#AddGoogleMap").click(function () {
if($('#googleMapCity').val() === "") {
alert("You need to fill out a city");
} else {
// do something
}
});