.context| jqueryAPI 2.2 中文手册- AspRain.cn 致力于Web开发技术翻译整理

jQuery API 2.2.0

.context

分类:建议弃用 > 建议弃用于1.10 | 内部 | 属性 > jQuery对象实例的属性

传递给jQuery()的原始DOM节点的上下文;如果没有传递任何上下文,则该上下文很有可能就是document。

返回: Element
弃用于:1.10

context

描述:The DOM node context originally passed to jQuery(); if none was passed then context will likely be the document.

加入于: 1.3
context

The .context property was deprecated in jQuery 1.10 and is only maintained to the extent needed for supporting .live() in the jQuery Migrate plugin. It may be removed without notice in a future version.

The .live() method for binding event handlers uses this property to determine the root element to use for its event delegation needs.

The value of this property is typically equal to document, as this is the default context for jQuery objects if none is supplied. The context may differ if, for example, the object was created by searching within an <iframe> or XML document.

Note that the context property may only apply to the elements originally selected by jQuery(), as it is possible for the user to add elements to the collection via methods such as .add() and these may have a different context.

示例

Determine the exact context used.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>context demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
Context: <ul></ul>
 
<script>
$( "ul" )
  .append( "<li>" + $( "ul" ).context + "</li>" )
  .append( "<li>" + $( "ul", document.body ).context.nodeName + "</li>" );
</script>
 
</body>
</html>

演示结果

如果网页上不能运行示例,请点击http://www.asprain.cn/jQueryAPI/context.htm查看示例。

如果你觉得本文档对你有用,欢迎给翻译作者支付宝打赏,支持翻译作者源源不断翻译更多有用的技术文档。