JavaScript 中的 $get 和 $find 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2726304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between $get and $find in JavaScript?
提问by Diskdrive
I'm a .NET programmer who've just started to learn more about client side scripting, and I was wondering sometimes you use $get('value')and $find('value')and I've discovered that these are just shortcuts for document.getElementById('value')and Sys.Application.findComponent('value'), respectively.
我是一名 .NET 程序员,刚刚开始学习有关客户端脚本的更多信息,我想知道您有时会使用$get('value')and$find('value')并且我发现这些分别只是document.getElementById('value')和 的快捷方式Sys.Application.findComponent('value')。
However, I still don't understand: what is the difference between these two functions in JavaScript? What exactly are they looking up/retrieving when invoked?
但是,我还是不明白:这两个函数在 JavaScript 中有什么区别?他们在调用时究竟在查找/检索什么?
Thanks in advance.
提前致谢。
回答by brendan
$get& $findare shortcut functions Microsoft has built into their Ajax JavaScript Library.
$get&$find是微软在他们的 Ajax JavaScript 库中内置的快捷功能。
$getis short for the standard JavaScript GetElementByIdfunction. $findis short for .Net's findComponent()function. This is not a standard JavaScript function and is specific to Microsoft's Ajax JavaScript library.
$get是标准 JavaScriptGetElementById函数的缩写。 $find是 .Net's findComponent()function 的缩写。这不是标准的 JavaScript 函数,而是特定于 Microsoft 的 Ajax JavaScript 库。
Matt Berseth does a great write up of the differences & usages here.
Matt Berseth在此处详细记录了差异和用法。
回答by Nenad
$get(elementId)returns a DOM element, same asdocument.getElementById(elementId)$find(elementId)returns an ASP.NET-AJAX JavaScript object, with it's own functions and properties.Inconveniently, in Microsoft Ajax those objects are always attached to some DOM element as it's attribute and are related to that DOM element in some ways, so that's why you have to pass element ID to retrieve the object data.
$get(elementId)返回一个 DOM 元素,与document.getElementById(elementId)$find(elementId)返回一个 ASP.NET-AJAX JavaScript 对象,带有它自己的函数和属性。不方便的是,在 Microsoft Ajax 中,这些对象总是附加到某个 DOM 元素,因为它是属性,并且在某些方面与该 DOM 元素相关,因此您必须传递元素 ID 来检索对象数据。
回答by Kurenai Kunai
$get is the shortcut function built by Microsoft into their ASP.net Ajax javascript library. It is short for getElementById method of javascript. It is not standard and is specific only to Microsoft.
$get 是 Microsoft 在其 ASP.net Ajax javascript 库中构建的快捷功能。它是 javascript 的 getElementById 方法的缩写。它不是标准的,仅适用于 Microsoft。
It accepts two parameters :
它接受两个参数:
- ID: id of the element. Required Field
- Element: Parent element to start the search. Optional Field
- ID:元素的ID。必填项目
- 元素:开始搜索的父元素。可选字段

