jQuery項目常用操作

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容