gpt4 book ai didi

javascript - 删除选择中每个选项的禁用属性

转载 作者:行者123 更新时间:2023-11-29 14:48:20 25 4
gpt4 key购买 nike

我有一个带有不同选项的选择。我将最近 30 秒内使用过的选项设置为禁用。我想要得到的是在条件不再有效但页面仍处于打开状态时再次启用选项。以下代码适用于一个选项,但由于它在 .each() 内部,因此每个选项都会被覆盖,因此不起作用。我正在考虑存储差异值的解决方法,向元素添加一个类并在具有该类的项目上运行 set timeout 但我认为这种代码不是最有效的。关于如何使用更高效的代码(可能在每个循环内?)获得相同结果的任何想法。

$('#destinatario option').each(function(){
var ds = $(this).attr('data-ts');
console.log("ts vale "+ds);
var dateArray = ds.split(" "); // split the date and time
var ds1 = dateArray[0].split("-"); // split each parts in date
var ds2 = dateArray[1].split(":"); // split each parts in time
var newDate = new Date(ds1[0], (+ds1[1] - 1), ds1[2], ds2[0], ds2[1], ds2[2]).getTime(); //parse it
console.log("allora vale "+newDate);
var currentDate = new Date().getTime();
console.log("adesso vale "+currentDate);
var diff = currentDate - newDate;
console.log(diff);
if(diff < 30000){
$(this).prop('disabled', true);
setTimeout(function() {
$(this).prop('disabled', false);
}, (30000-diff));
}
});

最佳答案

我有同样的情况,问题是我有一个循环,想为每个循环绑定(bind)一个更改回调,我发现所有这些都只适用于最后一个 ID 并解决它我做了以下绑定(bind)调用回调时的参数,以便它保存状态:

var arr = ["id1" ,"id2", "id3"];
for(i=0; i<arr.length; i++){
jQuery("#form_target_input").bind('change',function (id, e){
yiel.fn.setCookie("form_targeting_"+id, true)
}.bind(null, id));
}

针对您的情况:

setTimeout(function(element, e) {
$(element).prop('disabled', false);
}.bind(null, this), (30000-diff));

关于javascript - 删除选择中每个选项的禁用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29750361/

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