我有一个多选下拉列表的以下javascript,其复选框在IE中运行正常:
function checkAll(textId, checkId, hiddenId) {
var checkBox1 = document.getElementById(checkId);
var textElement = document.getElementById(textId);
var hiddenElement = document.getElementById(hiddenId);
if (checkBox1.checked) {
for (var item in window[textId]) {
if (typeof window[textId][item] != "function") {
var checkBox = document.getElementById(item);
if (window[textId][item].text != "Not Supported")
try
{
checkBox.checked = true;
}
catch (exception)
{
}
if (window[textId][item].text != "Select/De-select All" && window[textId][item].text != "Not Supported")
textElement.value += window[textId][item].text + ", ";
hiddenElement.value += window[textId][item].value + "|";
}
}
}
else if (!checkBox1.checked) {
for (var item in window[textId]) {
if (typeof window[textId][item] != "function") {
var checkBox = document.getElementById(item);
checkBox.checked = false;
textElement.value = "";
hiddenElement.value = 0;
}
}
}
}
然而,在Chrome中它不起作用。问题是这一行
for (var item in window[textId])
为var项指定实际的复选框ID
ctl00_MainContent_TabContainer1_TabPanel1_Multiselect1_ctl01
在IE中。但是,在Chrome中,这会为项目分配一个名为“webkitEntries”的东西,这不是我要找的东西。 btw textID这里是父控件的ID
ctl00_MainContent_TabContainer1_TabPanel1_Multiselect1_TextControl
有谁知道如何获取Chrome中每个的复选框ID?非常感谢和道歉 - 我对js来说很新鲜