jQuery獲取或設定元素的屬性值

2021-10-11 10:25:17 字數 522 閱讀 9984

獲取元素屬性值

//html**

//jquery**(記得引入jquery檔案)

console.log($('a').prop('href'));

//jquery**(記得引入jquery檔案)

console.log($('div').attr('index'));//1

設定元素的屬性值

//jquery**(記得引入jquery檔案)

$('a').prop('href','');//將a標籤的href屬性改為www.jidong.com

$('input').prop('type',"submit');//將單選按鈕改為提交框

//jquery**(記得引入jquery檔案)

$('div'.attr('index',2));//將自定義屬性index的值改為2

Jquery獲取 設定各種input元素的值

radio按鈕 input name kstype checked val name kstype 的radio按鈕集合中被選中的那個radio的value 文字框 var str txtname val 獲得文字框的值 txtname focus function 文字框獲取焦點 txtname ...

jquery獲取父元素或父節點的方法

jquery獲取父元素方法比較多,比如parent parents closest 這些都能幫你實現查詢父元素或節點,下面我們來一一講解 先舉個例子,jquery獲取父節點a li jquery獲取父元素a li ul 我們的目的是通過 id 為 item1 的便簽a取到 class 為 paren...

使用jquery獲取父元素或父節點

使用jquery獲取父元素或父節點,比較簡單,jquery提供了豐富的方法來讓我們使用jquery獲取父元素或父節點 jquery獲取父元素方法比較多,比如parent parents closest 這些都能幫你實現查詢父元素或節點,下面我們來一一講解 先舉個例子,我們的目的是通過 id 為 it...