jquery_1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery_1相关的知识,希望对你有一定的参考价值。

jqury

1.alt VS title
when your img does not show up,then you will see the alt on the page;
and when mouseover the img,what you see is title;

2.attr()
get arrtibute value: you can use the function attr("attr_name") to access the attribute;
also,you can set the attribute by the reload function attr("attr_name","attr_value");
example:
var txt = $("#myimg").attr("title"); //get the value of attribute title of myimg;
$("p").attr("text",txt); //then set value of title to all the tag <p>‘s text;

3.addClass()
we can add a defined class to the element of DOM by use to addClass() function;

4.css()
we can access the CSS of DOM elements;
like:$("p").css("background-color","yellow");//to set the background of all <p> to yellow;
$("p").css({color:red,background-color:yellow,font-size:16px});//set multiple css items;

5.removeClass();
remove the class of elements;

6.html()
get the html(contents) of elements(which means the innerHTML);

7.eq()
for DOM traversing,jquery have the function eq(index);
like:seek for the third li of ul:$("li").eq(2); //careful,the selector is not ul but li;

8.filter(selector)
this function allow you to filter out the elements by selector;
like:$("li").filter(".middle").addClass("selected");
//get all the li,then filter out the class = middle,the set their class to seletes;

9.find(selector);
use this function ,we can find the child elements right in the range we get;
like:$("p").find("span").addClass("selected");
//get all the <p> elements,the find all its <span> children elements;

10.width(value),height(value)
set the width or height of selectors;
like:$("div:first").width(100);//set the first div‘s width to 100;

11.html() VS text()
the function html() alaways mathch the innerHTML of the first selector
while the function text() match the innerHTML of all the selectors;

12. dl dt dd;
dictionary list;dictionary theme; dictionary data;

13.replaceWith(content)
replace the innerHTML of selector;
like:$("div").relaceWith("<h1>Hello World!</p>");

14.remove()
remove all the innerHTML of matched selectors;
like:$("div").remove();

15.after(),before();
insert the html after or before the selector;
like:$("div").after("<div class = "myDiv"><p>Hello World!</p></div>");

16.append() VS after()
append() means to append to the selector‘s innerHTML;
while the after() is to insert the selector‘s HTML;

以上是关于jquery_1的主要内容,如果未能解决你的问题,请参考以下文章

与同一页面上的两个 jquery 日期选择器冲突

我的学习之路_第二十七章_jQuery

JQuery添加删除标签

python学习_day58_前端基础之jQuery入门1

jquery_核心_

jquery的validate的用法