checkbox、radiobox、select常用操作

checkbox选中、不选中及事件绑定

//<input type='checkbox' id='checkbox'>
$('#checkbox').is(':checked'); // get check state
$('#checkbox').prop('checked', true); //check the box
$('#checkbox').on('change', function(){
   // do something
 });
$('#checkbox').on('click', function(){
   // do something
 });

radiobox选中、不选中及组合

// assume two radio in a group 
//<input type='radio' id='radio1' name='radio'>
//<input type='radio' id='radio2' name='radio'>
$('input[type=radio] :checked')   //get checked radio in group
$('input[type=radio]').filter(':checked') // get checked radio in group
$('#radio1').prop('checked', true) //check the radio
$('#radio1').is(':checked')  //get check state

select选中option及获取值

/*
<select>
<option value='v0'>0</option>
<option value='v1'>1</option>
</select>
*/
$('select option:selected').val() //get selected option value
$('select option:selected').text() // get selected option text
$('select').val() //get selected option value
$('select').text()// get all the options text(01), do not do this
$('select').val('v1') //trigger select to select option with value v1
$('select option:first').prop('selected', true) //select the first option
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • HTML标签解释大全 一、HTML标记 标签:!DOCTYPE 说明:指定了 HTML 文档遵循的文档类型定义(D...
    米塔塔阅读 3,331评论 1 41
  • 参考jquery操作select(增加,删除,清空)。 jQuery获取Select选择的Text和Value: ...
    Shirley_奋进中的虾米阅读 559评论 0 4
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • 1、窗体 1、常用属性 (1)Name属性:用来获取或设置窗体的名称,在应用程序中可通过Name属性来引用窗体。 ...
    Moment__格调阅读 4,606评论 0 11
  • 我出生那年,97年,她正好来到这。 她的模样说不上难看,但确实没啥特点。微卷的棕发,看起来还有点蔫。 自有意识起她...
    过者不过阅读 172评论 1 2