2017-05-08 66 views
1

我有以下代碼。顯示()方法在jquery不工作

$(document).ready(function() { 
    var factoryImage = document.getElementById("photo"); 
    factoryImage.src = document.getElementById('<%= FactoryImageFileNameHF.ClientID %>').value; 
    factoryImage.show(); 
}); 

我有jQuery的以下腳本源代碼。

<script src="/Scripts/jquery-3.0.0.min.js" type="text/javascript"></script> 

我收到以下錯誤消息。

jQuery.Deferred exception: factoryImage.show is not a function TypeError: factoryImage.show is not a function 
at HTMLDocument.<anonymous> (http://localhost:3373/Intranet/OHS/InteractiveMap/FactoryLayoutSettings.aspx:403:38) 
at j (http://localhost:3373/Scripts/jquery-3.0.0.min.js:2:29588) 
at k (http://localhost:3373/Scripts/jquery-3.0.0.min.js:2:29902) undefined 

這就行了factoryImage.show();

這裏是圖像

<img id="photo" src="/Icons/Factory Layout.png" style="display:none"/> 

,我可以確認在jQuery的那個factoryImage不爲空或未定義。 有些東西我錯過了,我知道這很容易,但我無法弄清楚。爲什麼show方法不起作用?

回答

3

的問題是,factoryImage不是一個jQuery的元素,但DOM元素,這應該工作

$(document).ready(function() { 
    var factoryImage = $("#photo");       
    factoryImage.attr("src", document.getElementById('<%= FactoryImageFileNameHF.ClientID %>').value); 
    factoryImage.show(); 
}); 
+0

謝謝。這工作。 –