jQuery中的RadioButton,input,CheckBox取值赋值实现代码

PHP中文网
Release: 2023-02-28 18:18:01
Original
1639 people have browsed it

1、jquery 获取单选组radio

$("input[name='name']:checked").val();
Copy after login

2、jquery获取radiobutton的下一个值

$("input[name='name']:checked").next().text()$("input[name='name']:checked").val()
Copy after login

3、jquery 获取input的值

$('#id').val()
Copy after login

4、jquery判断多选框checkbox

$("#id:checkbox").attr("checked") 取值 $("#id").attr("value");
Copy after login

赋值则是在text()、val()里面直接给值

JQUERY如何获取text,areatext,radio,checkbox,select值?

$("input").val(); $("textarea").text(); $("select").val();
Copy after login

控制表单元素:
文本框,文本区域:$("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容
多选框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾

单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项

下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项
$("

jQuery 获取和设置select下拉框的值文章分类:.net编程

获取Select :
获取select 选中的 text :

$("#ddlRegType").find("option:selected").text();
Copy after login

获取select选中的 value:

$("#ddlRegType ").val();
Copy after login

获取select选中的索引:

$("#ddlRegType ").get(0).selectedIndex;
Copy after login

设置select:
设置select 选中的索引:

$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值
Copy after login

设置select 选中的value:

$("#ddlRegType ").attr("value","Normal“); $("#ddlRegType ").val("Normal"); $("#ddlRegType ").get(0).value = value;
Copy after login

设置select 选中的text:

var count=$("#ddlRegType option").length; for(var i=0;i
        
Copy after login

设置select option项:

$("#select_id").append("
Copy after login

清空 Select:

$("#ddlRegType ").empty();
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!