Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$([selector,[context]])实现 #4

Open
jaywcjlove opened this issue Mar 19, 2015 · 0 comments
Open

$([selector,[context]])实现 #4

jaywcjlove opened this issue Mar 19, 2015 · 0 comments

Comments

@jaywcjlove
Copy link
Member

1.【zepto实现的效果】创建带有属性的元素

$("<p />", { text:"Hello", id:"greeting", css:{color:'darkblue'} })

2.【jQuery实现的效果】如果没有指定context参数,$()将在当前的 HTML document中查找 DOM 元素;如果指定了 context 参数,如一个 DOM 元素集或 jQuery 对象,那就会在这个 context 中查找。context: 作为待查找的 DOM 元素集、文档或 jQuery 对象。

在文档的第一个表单中,查找所有的单选按钮(即: type 值为 radio 的 input 元素)。

$("input:radio", document.forms[0]);

在一个由 AJAX 返回的 XML 文档中,查找所有的 div 元素。

$("div", xml.responseXML);
@jaywcjlove jaywcjlove changed the title $(selector, context) 实现 $([selector,[context]])实现 Mar 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant