2014-09-02 71 views
0

我试图使用新的 HTML element。下面是一些测试代码:jQuery和<dialog>元素

<dialog id="addSystemDialog"> 
    <p>This is a dialog</p> 
    <button id='close'>Close dialog</button> 
</dialog> 
<button id='show'>Show add dialog</button> 

而且在JS:

var dialog = document.querySelector('dialog'); 
document.querySelector('#show').onclick = function() { 
    dialog.show(); 
}; 
document.querySelector('#close').onclick = function() { 
    dialog.close(); 
}; 

如果我改变了第一JS行

var dialog = $('dialog'); 

它不再起作用。为什么?

+0

你在页面中包含了jQuery吗? – 2014-09-02 22:20:51

回答

1

document.querySelector返回第一个匹配。

jQuery返回所有匹配的数组

如果您使用$('dialog')[0],则应该得到相同的结果。