我應該從提及我使用Internet Explorer 6開始。我從onChange
事件調用JavaScript函數(tabModifiedHighlight
)。然而,該功能在其他地方完美運行,當我檢查複選框時,我在頁面上有幾個位置,但是當我取消選中該複選框時,事件似乎不會觸發。 這裏是JavaScript函數:在檢查複選框時調用函數,取消選中時onclick事件不會觸發
function tabModifiedHighlight(){
alert("alert");
var div, i, input, inputIndex, selects, selectIndex, selectedTab, highlighted;
var tabs = new Array("admissioninformation","diet","vitalsigns","activities","nursing","ivfluids","medications1","medications2","labs","respiratory","diagnostic","consultations");
for(i=0; i<(tabs.length); i++){
selectedTab = tabs[i]+'tab';
if (document.getElementById(selectedTab).className == "selectedtab"){
div = document.getElementById(tabs[i]),
input = div.getElementsByTagName('input'),
selects = div.getElementsByTagName('select');
break;
}
}
highlighted = false;
for (inputIndex = 0; inputIndex < input.length; inputIndex++){
if (input[inputIndex].checked == true){
highlighted = true;
}
}
for (inputIndex = 0; inputIndex < input.length; inputIndex++){
if (input[inputIndex].type == 'text' && input[inputIndex].value != ""){
highlighted = true;
}
}
for (selectIndex = 0; selectIndex < selects.length; selectIndex++){
if (selects[selectIndex].value != ""){
highlighted = true;
}
}
if (highlighted == true){
document.getElementById(selectedTab).style.backgroundColor = "#FF0";
}
else {
document.getElementById(selectedTab).style.backgroundColor = "#F0F0F0";
}
}
這裏是調用它的輸入:
<input name="cbMedTylenolPO" id="cbMedTylenolPO" type="checkbox" value="PO" onClick="tylenolPoShowHide(); checkBoxHighlight(this, 'MedicationsRow2'); tabModifiedHighlight();" />
這個頁面有多個「標籤」,它只是被設置的div基於選擇哪一個來顯示或隱藏。看起來一致的是,除了2個選項卡以外,它在任何地方都可以工作,並且在這些選項卡上無處可用。我能看到的唯一的另一個區別是,那些不工作的人也顯示或隱藏標籤中的div,根據複選框是否被選中。我在函數的最開始處添加了警報,以查看它是否正在觸發,它在檢查複選框時執行,但在取消選中時不執行。
我希望我明確這一點,並感謝任何想法!
非常感謝!通過按照您的建議將警報添加到其他功能的開始和結束處進行調試,我可以確定它何時啓動實際上是在另一個功能的開始和結束之間。仔細檢查後,我意識到如果複選框被選中,另一個函數調用tabModifiedHighlight函數。我仍然不知道爲什麼它不會在onClick事件中調用函數,而是通過修改其他函數來調用它,無論是否選中,我都能夠解決它,以便它每次都能正常工作現在。謝謝! – nherrmann 2013-05-13 15:05:58