文档选择器和窗口选择器有什么区别?

编程入门 行业动态 更新时间:2024-10-27 04:31:15
本文介绍了文档选择器和窗口选择器有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下JQuery函数,它接受用户输入并将其显示在屏幕上.当我同时选择$(document)和$(window)时,该功能有效.使用任何一个选择器的缺点是什么?我在哪里可以阅读有关这些选择器及其区别的更多信息?

I have the following JQuery function that takes user input and displays it on screen. When I select for both $(document) and $(window) the function works. What is the disadvantage to using either selector? Where can I read more on these selectors and their differences?

先谢谢您.

$(document).keypress(function(e) { if(e.keyCode == 13) { var id = $("input#example").val() console.log(id); $('#data').append(id); } });

推荐答案

同时在window或document对象rel ="noreferrer"> jQuery dom选择器,大多数时候您不会注意到两者之间的区别.

While using the window or document object in a jQuery dom selector, most of the time you won't notice a difference between the two.

但是,重要的是要注意它们不是同一对象.

However, it's important to note that they are not the same object.

window-引用视口.它用作JavaScript中的主要全局对象. document-window的直接后代;指文档树的根.

window - refers to the viewport. It's used as the main global object in JavaScript. document - a direct descendant of window; refers to the root of the document tree.

所有DOM元素都是document的后代,而document是window的直接后代.

All DOM elements are a descendant of the document, which is a direct descendant of window.

更多推荐

文档选择器和窗口选择器有什么区别?

本文发布于:2023-11-28 14:47:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选择器   有什么区别   窗口   文档

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!