html() 方法返回或設置被選元素的內(nèi)容 (inner HTML)。
$(".btn").click(function(){
$("p").html("Hello <b>world</b>!");
});
findIndex和toString結(jié)合使用查找當前item是處于數(shù)組中第幾項
itemNum = table_list.findIndex(function(item){
return item.toString() == myItem.toString()
})
val() 方法返回或設置被選元素的值。
$("button").click(function(){
$(":text").val("Hello World");
});
獲取select選中項中存在data里面的值
<select class="mySelect">
<option value="switch" data-name="開關">開關</option>
<option value="light" data-name="燈光">燈光</option>
</select>
好,現(xiàn)在用jquery進行操作
頁面上展示的是標簽里面的“開關”;
$(".mySelect").find("option:selected").attr("data-name"); 獲取選中項的data-name的值“開關”;
$(".mySelect").val();獲取value的值switch。
parseInt 將XX轉(zhuǎn)化為number類型
indexOf 判斷myitem是否存在于itemArray數(shù)組中,存在返回第一個索引,否則返回-1
var index = JSON.stringify(itemArray).indexOf(JSON.stringify(myitem));
append 往文檔中插入需要的html和值
$(".btn").click(function () {
html = '<tr>'
+ '<td>' + '<img src="./images/item.png" alt="">' + '</td>'
+ '<td>' + '<span>品牌:</span>' + '<span>' + $(".myValue").val() + '</span>' + '</td>'
+ '</tr>';
$(".list").append(html);
});
location.reload() 刷新頁面
attr() 和removeAttr()
$(".input").attr("placeholder", "請輸入您的號碼");
$(".input").removeAttr("data-target");
prop() 和 removeprop()
<label>
<input class="input" type="checkbox" value="復選框" checked = "true" disabled = "">
</label>
用prop獲取復選框中checked的值(true)
$(".input").prop("checked"); //true
w3c官網(wǎng)http://www.w3school.com.cn/jquery/jquery_ref_attributes.asp