您的位置:首页 > Web前端 > JQuery

jQuery对下拉框、单选框、多选框的处理

2009-02-19 12:38 591 查看
下拉框:

view plaincopy to clipboardprint?

//得到下拉菜单的选中项的文本(注意中间有空格)

var cc1 = $(".formc select[@name='country'] option[@selected]").text();

//得到下拉菜单的选中项的值

var cc2 = $('.formc select[@name="country"]').val();

//得到下拉菜单的选中项的ID属性值

var cc3 = $('.formc select[@name="country"]').attr("id");

//清空下拉框//

$("#select").empty();$("#select").html('');

//添加下拉框的option

$("<option value='1'>1111</option>").appendTo("#select")

//得到下拉菜单的选中项的文本(注意中间有空格)
var cc1 = $(".formc select[@name='country'] option[@selected]").text();

//得到下拉菜单的选中项的值
var cc2 = $('.formc select[@name="country"]').val();

//得到下拉菜单的选中项的ID属性值
var cc3 = $('.formc select[@name="country"]').attr("id");

//清空下拉框//
$("#select").empty();$("#select").html('');

//添加下拉框的option
$("<option value='1'>1111</option>").appendTo("#select")


单选框:

view plaincopy to clipboardprint?

//得到单选框的选中项的值(注意中间没有空格)

$("input[@type=radio][@checked]").val();

//设置单选框value=2的为选中状态.(注意中间没有空格)

$("input[@type=radio][@value=2]").attr("checked",'checked');

//得到单选框的选中项的值(注意中间没有空格)
$("input[@type=radio][@checked]").val();

//设置单选框value=2的为选中状态.(注意中间没有空格)
$("input[@type=radio][@value=2]").attr("checked",'checked');


复选框:

view plaincopy to clipboardprint?

//得到复选框的选中的第一项的值

$("input[@type=checkbox][@checked]").val();

//由于复选框一般选中的是多个,所以可以循环输出

$("input[@type=checkbox][@checked]").each(function(){

alert($(this).val());

});

//不打勾

$("#chk1").attr("checked",'');

//打勾

$("#chk2").attr("checked",true);

//判断是否已经打勾

if($("#chk1").attr('checked')==undefined){}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: