如何验证城市

我通常会使用:

        if ($("#parkState").val() == "0") {
            alert("Please select a state.");
        }


<option>Select a city</option>
<option>city1</option>
<option>city2</option>
<option>city3</option>

但我这里没有价值观。 如何针对“选择城市”测试我的if语句?

采纳答案:

您可以使用$('#parkState option:selected').text()来获取Select a city

if ($('#parkState option:selected').text() == 'Select a city') {
  alert('Please select a state.');
}

参考更多解答: How to verify city ,转载请保留出处如何验证城市及作者信息

Statement: We respect knowledge and authors. Since the content comes from the Internet and is intended for scientific research, any reprinters should retain the author's signature and origin. If you are the author of the content and feel in dispute, please contact email: 1076545519@qq.com. We will find out the situation and deal with it in time. We sincerely thank the author for his hard work.


更多:jquery