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

2014-11-24 07:56:43 · 作者: · 浏览: 3

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”.

Male
Female
Unknown
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);