2013-04-27 32 views
0

我有我的文件下面的HTML代碼上傳從PHP上傳表單呼應jQuery腳本在使用iframe的

<div id="status"></div> 

<iframe name="upifrm" src="" style="display:none;"></iframe> 

<form name="myForm" id="myForm" action="upload.php" method="post" enctype="multipart/form-data" target="upifrm"> 
<label for="fileinput" id="brsbtn" class="labtrigg">label</label> 
<input type="file" id="fileinput" name="file" /> 
</form> 

<div id="atchs"></div> 

,並在我的upload.php的文件的最後,我有

// . . . . . . . . . . . . .  
// $message declaration . . . 

echo '<script> 
parent.document.getElementById("myForm").reset(); 
parent.document.getElementById("status").innerHTML="'.$message.'"; 
$("#atchs", window.parent.document).after("<span>something</span>"); 
</script>'; 

前兩行完美地工作(它們是用純Javascript代碼編寫的),但我得到第三行的錯誤

$("#atchs", window.parent.document).after("<span>something</span>"); 

「預期的對象」。我怎麼解決這個問題?

+0

你叫'$( 「#atchs」,window.parent.document)你的父頁面。( 「東西」);'在你的iframe中?你有jQuery包含在iframe中嗎? – 2013-04-27 13:55:50

+0

你的前兩行是傳統的js,你爲什麼要在第三行使用jQuery方法? – Rikesh 2013-04-27 13:57:09

+0

我在我的主要HTML文件中包含了jQuery。 Iframe在這個HTML文件上。 Rikesh,我想用jQuery重寫整個代碼,所以上面的代碼只是一個例子。謝謝。 – Paramore 2013-04-27 14:01:55

回答

0

試試這個 確保在揮霍包括jQuery文件

top.jQuery("#atchs").html("<span>something</span>"); 

希望這是有道理的

+0

非常感謝Dianuj! – Paramore 2013-04-27 14:14:30

+0

歡迎您:) – 2013-04-27 14:33:30

0

即使你已經包括jQuery的,應該有一個函數名的位置:

$("#atchs", window.parent.document).("<span>something</span>"); 
            ^^^ 

喜歡的東西appendprependhtmltext,或者你正在試圖做的。它不能只是一個圓點和圓括號。