歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> jQuery去掉字符串起始和結尾的空格

jQuery去掉字符串起始和結尾的空格

日期:2017/3/1 9:59:46   编辑:Linux編程

jQuery去掉字符串起始和結尾的空格。

jQuery 代碼:
$.trim(" hello, how are you? ");


jquery 循環讀取checkbox值
復制代碼 代碼如下:
$("input[type=checkbox][checked]").each(function(){ //由於復選框一般選中的是多個,所以可以循環輸出
alert($(this).val());
});

$("#A").val("1") id為A的值就是1了 jQuery中都這樣,賦值的時候作為參數傳給函數,和單純的js有區別,像$("#A").html("1")$("#A").text("1") 都是賦值 $("#A").html() $("#A").text() 都是取值,取html,

取text文本


方法一:

$('#id').css('display','none');

$('#id').css('display','block');

方法二:

$('#id').hide();

$('#id').show();



radio 按鈕組, name=”sex”.

<input type="radio" name="sex" value="Male">Male</input>
<input type="radio" name="sex" value="Female">Female</input>
<input type="radio" name="sex" value="Unknown">Unknown</input>
1. 獲取radio選中的value.

$('input:radio[name=sex]:checked').val();

2. 選擇 radio 按鈕 (Male).

$('input:radio[name=sex]:nth(0)').attr('checked',true);
或者
$('input:radio[name=sex]')[0].checked = true;

3. 選擇 radio 按鈕 (Female).

$('input:radio[name=sex]:nth(1)').attr('checked',true);
或者
$('input:radio[name=sex]')[1].checked = true;

4. 選擇 radio 按鈕 (Unknown).

$('input:radio[name=sex]:nth(2)').attr('checked',true);
或者
$('input:radio[name=sex]')[2].checked = true;

5. 重置 radio 按鈕.

$('input:radio[name=sex]').attr('checked',false);

Copyright © Linux教程網 All Rights Reserved