gpt4 book ai didi

javascript 根据其他下拉列表更改下拉列表值

转载 作者:搜寻专家 更新时间:2023-11-01 04:27:31 25 4
gpt4 key购买 nike

I have a requirement When selected a dropdown value, it has to filter or remove the values of other dropdown which has index that should be always greater than selected index of first dropdown.

例如:第一个下拉值:

01:00
01:30
02:00 // suppose i select 02:00 here
02:30
03:00
03:30
04:00
04:30
05:00
05:30

第二个 Dropdonw 值(在上面的下拉列表中选择的 02:00 应该如下所示)

02:30
03:00
03:30
04:00
04:30
05:00
05:30

(我在这里使用 C# 和 Asp.net。)

任何实现上述目标的 javascript 都将不胜感激

并按照 Salman 建议使用如下脚本

<body onload="select()">
<script language="javascript">
function select(){
var select1 = document.getElementById("ddlFrom");
var select2 = document.getElementById("ddlTo");
select1.onchange = function filterDDL() { // empty select2
while (select2.firstChild) {
select2.removeChild(select2.firstChild);
}
if (select1.selectedIndex == 0)
{
return;
}
for (var i = select1.selectedIndex; i < select1.options.length; i++)
{
var o = document.createElement("option");
o.value = select1.options[i].value;
o.text = select1.options[i].text;
select2.appendChild(o);

}
}
}</script>

但不工作...请帮助解决这个问题提前致谢

最佳答案

编辑(使用 jQuery 获得所需结果):

<select id="one">
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="02:30">02:30</option>
<option value="03:00">03:00</option>
<option value="03:30">03:30</option>
</select>

<select id="two"></select>

<script type="text/javascript">
$(function () {
$("#one").change(function (e) {
$("#two").empty();

var options =
$("#one option").filter(function(e){
return $(this).attr("value") > $("#one option:selected").val();
}).clone();

$("#two").append(options);
});
});
</script>

关于javascript 根据其他下拉列表更改下拉列表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5990552/

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