निम्नलिखित कोड क्रोम में एक समस्या के बिना चलाया जा सकता है में ठीक काम करता है, लेकिन इंटरनेट एक्सप्लोरर में निम्न त्रुटि 11.कोड IE 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>
आपको इसके बजाय IE के लिए 'str.indexOf ("REP") == 0' का उपयोग करने की आवश्यकता होगी। –
ES6 अभी तक मानक नहीं है https://kangax.github.io/compat-table/es6/ संक्रमण की सहायता के लिए एक ES6 शिम लाइब्रेरी है https://github.com/paulmillr/es6-shim/ बस इसी तरह की ES5 (सब कुछ शामिल नहीं है) – Xotic750