我有以下代码。
$(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不为null或未定义。 有一些我想念的东西,我知道这很容易,但我无法弄清楚。为什么show方法不起作用?
答案 0 :(得分:3)
问题是factoryImage
不是jQuery元素而是DOM元素,这应该可行
$(document).ready(function () {
var factoryImage = $("#photo");
factoryImage.attr("src", document.getElementById('<%= FactoryImageFileNameHF.ClientID %>').value);
factoryImage.show();
});