gpt4 book ai didi

javascript - 检查 selectBox 中的元素 id-value(下拉列表)

转载 作者:行者123 更新时间:2023-11-28 01:56:04 24 4
gpt4 key购买 nike

我想检查我的选择框是否有 ID。

这是我的代码:

<select name="startTime" id="startTime">
<option>23:00</option>
<option id="nextDay">00:30</option>
</select>

现在我想检查用户是否有正常的(23:00)。或者 id="nextDay"的那个。

所以它会是这样的检查:

if(selected has id="nextDay"){ //Than do something}

如何使用 javascript 和/或 jquery 做到这一点?这是我想要的简化版本。

最佳答案

$(document).ready(function(){

$("#startTime").change(function(){ // this can also be a form submit or something
if($("#nextDay").is(":selected"))
{
alert("Working!");
//do something
}
});
});

这应该有效;)!在之前的解决方案中,代码是在页面加载时执行的,而不是在进行选择时执行的。

关于javascript - 检查 selectBox 中的元素 id-value(下拉列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19096667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com