2016-01-05 30 views
-1

代码:

var zoomPopup = document.getElementById('image-zoom'); 
zoomPopup.hide(); 

一些其他的代码

$('#container').find('.zoomImage').on('click', function() { 
     zoomPopup.show(); 
     $(zoomPopup).html('<img src="/static/on.png" height="64px" width="64px">'); 
     console.log('adres: ' + this.src); 
}); 

如果我尝试写不$()

zoomPopup.html('<img src="/static/on.png" height="64px" width="64px">'); 

我得到一个错误:

Uncaught TypeError: zoomPopup.html is not a function

为什么?为什么zoomPopup.show()工作正常?

+0

zoomPopup.html()将不起作用,并且在正常情况下,zoomPopup.hide()或show()不起作用。因为它不是一个JavaScript函数,例如:这是一个js函数document.getElementById(“demo”)。innerHTML =“Paragraph changed!”; ---或为您的情况zoomPopup.innerHTML(''); – Arthur

回答

2

因为你是在jQuery和纯javascript之间进行混合。您只能使用jQuery的:

$(document).ready(function(){ 
    var zoomPopup = $('#image-zoom'); 
    zoomPopup.hide(); 

    $('#container').find('.zoomImage').on('click', function() { 
     zoomPopup.html('<img src="/static/on.png" height="64px" width="64px">').show(); 
     console.log('adres: ' + $(this).attr('src')); 
    }); 
}); 

我敢肯定zoomPopup.show()不工作,还有.hide()方法,因为它们不是DOM元素的方法。由于元素永远不会隐藏,所以您认为show方法有效,但不是。

+0

奇怪,这是.hide的工作,以及.show()这是一个完整的页面弹出与白色背景,所以当我注释掉zoomPopup.hide()我可以看到它。 –

+0

尝试评论'zoomPopup.show()'..如果你仍然看到该元素,那么明确表示'.hide()'方法不工作..也..控制台应该注意到,这两种方法不存在物体 –

相关问题