jQuery中選擇器加尖括號的區別
阿新 • • 發佈:2018-12-25
$("img")為一個get的方法,是讀取標籤為"img"元素的屬性及設定相應的屬性;
$("<img/>")為一個set的方法,是建立一個新的標籤元素"img"並賦予相應標籤相應的屬性
舉例:$(document).ready(function(){findDogs();
});
function findDogs(){
$.post("/finddogs",null,
function(data){
$.each(data,function(){
var tr = $("<tr/>");
$("<img/>").attr("src","images/"+this.image).attr("height",60).attr("width",60).appendTo("<td/>").appendTo(tr);
$("<td/>").html(this.name).appendTo(tr);
$("<td/>").html(this.price).appendTo(tr);
$("#dogtable").append(tr);
})
},"json");
}