2013-02-14 80 views
0

我有寫在我的元件如下:奇怪:功能沒有定義

<form name="myform" method="POST" id="location"> 
<input type="text" name="URL" maxlength="255" size="100" value="" /> 
<br /> 
<input type="button" onclick="loadXML(this.form)" name="submit" value="Submit Query" /> 
</form> 

然後我已經在部分中所定義的我的函數的loadXML();但每次我試圖運行這個網站,火狐顯示了這個:

的ReferenceError:loadXML的沒有定義 的loadXML(this.form)

我已經檢查了我的代碼,那麼多次,我相信沒有拼寫錯誤,這是怎麼發生的?我該如何糾正它?謝謝!

+0

定義您的loadXML函數在哪裏? – 2013-02-14 00:30:33

+0

在中,我編寫了中的所有javascript。 – lkkeepmoving 2013-02-14 00:44:04

+0

你可以發佈頭部分嗎?你確定它被定義爲一個全局函數嗎? – Iwan 2013-02-15 16:49:37

回答

1

loadXML僅在IE中可用。否則,您想使用DOMParser對象。事實上,我將依靠現有的第一:

if (typeof DOMParser !== 'undefined') { 
    var dom = new DOMParser(); 
    dom.parseFromString(this.form, "application/xml"); 
} 
else { 
    loadXML(this.form); 
} 
+0

這個html只會通過firefox加載,所以我不認爲這個問題與瀏覽器有關。最奇怪的是我明確定義了loadXML,但它表明我沒有。 – lkkeepmoving 2013-02-14 00:43:08