Jquery的一些基本用法

2021-07-24 01:22:33 字數 1125 閱讀 8184

1、獲取指定name的radio選定的值:var a=$("input[name='price']:checked").attr("value");

2、獲取指定id的html標籤中的文字內容:var a=$("#aa").text();

3、修改指定id的html標籤中的內容,html**也會以文字形式顯示:

$("#"+n).html('警告')

;4、保留小數點後的兩位:a.tofixed(2)

;5、設定輸入框只能輸入數字和小數點:this.value=this.value.replace(/[^\d\.]/g,'');

6、設定input的value屬性:

$("#pingfen").val(title);

7、獲取指定id的特殊屬性值:var a=$("#aaa").attr("屬性名");

8、設定指定img的src:$("#img1").attr("src","imges/test.jpg");

9、設定指定標籤的樣式:$

("p").css("color","red");

10、獲取指定標籤樣式的值:var a=

$("#img1").css("width");

11、遍歷符合條件的所有節點:

$("#size_div ul").each(function () );

12、獲取select 選中的 text :$("#ddlregtype").find("option:selected").text();

13、獲取select選中的 value:

$("#ddlregtype ").val();

14、獲取select選中的索引:

$("#ddlregtype ").get(0).selectedindex;

15、去掉字串首尾空格:$.trim("  a  a   "); 16

、獲取指定id的html標籤中的包括html**:

$("#"+n).html()

; 17

、在指定標籤中加入內容可包含html**:

$("#"+n)

18、擷取指定字串:

str.substring(

str.indexof(" pm") + 3, 

str.length);

jquery 的一些用法

prepend prependto 測試用的 我在box外面啊 jquery before和insertbefore用法 p before b 表示p的前面是b,也就是b要插到p的前面。p insertbefore b 表示將p插入到b的前面 使用after和before是新增同級的dom jque...

Jquery的一些基本操作

獲得text.areatext的值 var textval text id attr value 或者 var textval text id val 獲取單選按鈕的值 var valradio input type radio checked val 獲取一組名為 items 的radio被選中項...

jquery一些基本的語法

基本選擇器 id id選擇器 tagname 標籤選擇器,返回陣列 class 類選擇器,返回陣列 選擇文件中的所有的元素 e.c 選擇樣式名稱為c的e標記 e i 選擇id為i的e標記 層疊選擇器 e,f 選擇所有e元素和所有f元素 並集 e f 選擇e元素內部的所有f元素 子孫節點 e f 選擇...