我正在尝试使用新的HTML元素。下面是一些测试代码:
<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');它不再起作用了。为什么?
发布于 2014-09-02 22:22:24
document.querySelector返回第一个匹配。
jQuery返回所有匹配的数组。
如果您使用$('dialog')[0],您应该得到相同的结果。
https://stackoverflow.com/questions/25633237
复制相似问题