爲什麼這個簡單的東西在IE 9中不起作用?它工作得很好,我FF和Chrome。SCRIPT5007 IE9 getElementsByTagName
<script language="javascript" type="text/javascript">
function displayBusinessCardData() {
var xmldata = document.getElementById("xmldata1");
var bizCard = xmldata.getElementsByTagName("BusinessCard")[0];
var name = "Name: " + bizCard.getElementsByTagName("name")[0].firstChild.data;
var phone1 = "Phone: " + bizCard.getElementsByTagName("phone")[0].firstChild.data;
var phone2 = "Phone: " + bizCard.getElementsByTagName("phone")[1].firstChild.data;
var phone3 = "Phone: " + bizCard.getElementsByTagName("phone")[2].firstChild.data;
var email = "Email: " + bizCard.getElementsByTagName("email")[0].firstChild.data;
alert("BusinessCard Data: \n\n" + name + "\n" + phone1 + "\n" + phone2 + "\n" + phone3 + "\n" + email);
}
</script>
<xml id="xmldata1" style="display:none">
<BusinessCard>
<name>Joe Marini</Name>
<phone type="mobile">(415) 555-4567</phone>
<phone type="work">(800) 555-9876</phone>
<phone type="fax">(510) 555-1234</phone>
<email>[email protected]</email>
</BusinessCard>
</xml>
<a href="javascript:displayBusinessCardData()">Show Business Card Data</a>
</body>
它失敗,並顯示「xmldata.getElementsByTagName(」BusinessCard「)[0];」結果bizCard爲空。
Thx Luc。這簡直是愚蠢的MS。他們是那些引入XML數據島的人,現在他們不再支持它了。 – Irina