js:
tr.style.display = 'table-row'; tr.style.display = 'none';jquery:
$("tr").show(); $("tr").hide();!0代表第一个元素下标
$(a).prop('selectedIndex', 0);------------------------第二种-------------------------------------
var keys = ''; $("input[name='checked[]']:checked").each(function(){ if(this.checked==true){ var value = this.value; keys += value += ','; } });var state = $(a).is(':checked'); $("input[name='checked[]']").each(function(){ this.checked = state; });
这里有个错误一开始 用的是attr修改元素 但多次点击会失效 已换用prop方法解决
function Switch(id,c_id){ var selects = $("#select"+id+" > select"); var frist = $("#select"+id+" > select:eq(0) > option"); var values = []; //获取允许数值的数组 $.each(frist,function(index,value){ values[index] = index; }); //循环所有下啦列表 for (i = 0; i < selects.length; i++) { var index = Math.floor((Math.random()*values.length)); var selected = values[index]; if(c_id==3 || c_id==4){ values.splice(index,1); var newarr = []; for (let [key, val] of values.entries()) { newarr[key] = val; } values = newarr; } $("#select"+id+" select:eq("+i+") option:eq("+selected+")").prop("selected",true); } }
