Javascript 为什么.html与$(x)一起工作,而与x不一起工作?

Javascript 为什么.html与$(x)一起工作,而与x不一起工作?,javascript,jquery,Javascript,Jquery,代码: 其他代码 var zoomPopup = document.getElementById('image-zoom'); zoomPopup.hide(); 我得到一个错误: 未捕获类型错误:zoomPopup.html不是函数 为什么?为什么zoomPopup.show工作正常?因为您混合了jQuery和纯javascript。您只能使用jQuery: zoomPopup.html('<img src="/static/on.png" height="64px" width="6

代码:

其他代码

var zoomPopup = document.getElementById('image-zoom');
zoomPopup.hide();
我得到一个错误:

未捕获类型错误:zoomPopup.html不是函数


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

因为您混合了jQuery和纯javascript。您只能使用jQuery:

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

我很确定zoomPopup.show和.hide方法都不起作用,因为它们不是DOM元素的方法。由于元素从不隐藏,您认为show方法可以工作,但不能。

zoomPopup.html将不起作用,通常情况下zoomPopup.hide或show也不起作用。因为它不是javascript函数,例如:这是一个js函数document.getElementByIddemo.innerHTML=段落更改!;-或者对于您的案例zoomPopup.innerHTML;这很奇怪。隐藏也可以。显示它是一个带有白色背景的完整页面弹出窗口,所以当我注释掉zoomPopup.hide时,我可以看到它。尝试注释zoomPopup.show。。如果仍然看到该元素,则很明显.hide方法不起作用。。而且控制台应该注意到对象不存在这两个方法
zoomPopup.html('<img src="/static/on.png" height="64px" width="64px">');
$(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'));
    });
});