标签:style http color os strong 数据
$( "a" ).attr( "href", "allMyHrefsAreTheSameNow.html" );
$( "a" ).attr({
title: "all titles are the same too!",
href: "somethingNew.html"
});
// Refining selections.
$( "div.foo" ).has( "p" ); // div.foo elements that contain <p> tags
$( "h1" ).not( ".bar" ); // h1 elements that don‘t have a class of bar
$( "ul li" ).filter( ".current" ); // unordered list items with class of current
$( "ul li" ).first(); // just the first unordered list item
$( "ul li" ).last();
$( "ul li" ).eq( 5 );
$( "#content" )
.find( "h3" )
.eq( 2 )
.html( "new text for the third h3!" )
.end() // Restores the selection to all h3s in #content
.eq( 0 )
.html( "new text for the first h3!" );
var btn1;
$("#1").on("click",function(){
alert($(this).html());
});
$("#remove").on("click",function(){
btn1 = $("#1").remove(); // 依次点击remove,back,1,将不会有任何东西alert
});
$("#back").on("click",function(){
$("body").append(btn1);
});
$("#detach").on("click",function(){
btn1 = $("#1").detach(); //依次点击detach,back,1将会弹出1
});
// Creating new elements from an HTML string.
$( "<p>This is a new paragraph</p>" );
$( "<li class=\"new\">new list item</li>" );
// Creating a new element with an attribute object.
$( "<a/>", {
html: "This is a <strong>new</strong> link",
"class": "new",
href: "foo.html"
});
var myItems = [];
var myList = $( "#myList" );
for ( var i = 0; i < 100; i++ ) {
myItems.push( "<li>item " + i + "</li>" );
}
myList.append( myItems.join( "" ) );
jQuery核心之DOM操作的常用方法,布布扣,bubuko.com
标签:style http color os strong 数据
原文地址:http://www.cnblogs.com/iceseal/p/3863945.html