निम्न कोड क्रोम में एक समस्या के बिना चलाया जा सकता है, लेकिन इंटरनेट एक्सप्लोरर 11 में निम्न त्रुटि को फेंकता है।
ऑब्जेक्ट संपत्ति या विधि का समर्थन नहीं करता है 'प्रारंभ'
मैं एक चर में तत्व की आईडी संग्रहीत कर रहा हूं। मामला क्या है?
function changeClass(elId) {
var array = document.getElementsByTagName('td');
for (var a = 0; a < array.length; a++) {
var str = array[a].id;
if (str.startsWith('REP')) {
if (str == elId) {
array[a].style.backgroundColor = "Blue";
array[a].style.color = "white";
} else {
array[a].style.backgroundColor = "";
array[a].style.color = "";
}
} else if (str.startsWith('D')) {
if (str == elId) {
array[a].style.backgroundColor = "Blue";
array[a].style.color = "white";
} else {
array[a].style.backgroundColor = "";
array[a].style.color = "";
}
}
}
}
<table>
<tr>
<td id="REP1" onclick="changeClass('REP1');">REPS</td>
<td id="td1"> </td>
</tr>
<tr>
<td id="td1"> </td>
<td id="D1" onclick="changeClass('D1');">Doors</td>
</tr>
<tr>
<td id="td1"> </td>
<td id="D12" onclick="changeClass('D12');">Doors</td>
</tr>
</table>
str.indexOf("REP") == 0इसके बजाय IE के लिए उपयोग करने की आवश्यकता होगी ।