Handling Checkboxes, Radio Buttons and Select Options in jQuery [转]
2010-07-01 14:09
701 查看
Handling Checkboxes, Radio Buttons and Select Options in jQuery
I figured I’d share how I’ve dealt with some form elements in jQuery. Sometimes you have to look at the docs a few times before you get what you can do, so I think these examples might help someone out there.Here is how you can handle a change in a dropdown (SELECT tag with an ID that is “layer_image”):
$("#layer_image").change(function() { switch ($(this).val()) { case '0': $("#radar_image").hide(); break; default: $("#radar_image").show(); } });
Granted I could of used toggle() to do the same thing I figured it was better to show an example using the switch statement.
Here is an example of handling a checkbox (INPUT tag with an name attribute of “option_linkwindow”):
$("input[@name='option_linkwindow']").click( function() { if ($("input[@name='option_linkwindow']").is(":checked")) $(".feed/ul>li/a").attr("target","_blank"); else $(".feed/ul>li/a").attr("target","_self"); $(this).blur(); } );
Here is another example of handling a checkbox (INPUT tag with a name attribute of “option_summary”):
$("#option_summary").change( function() { $("//li/p").toggle(); $("li[p:hidden]").removeClass("expanded"); $("li[p:visible]").addClass("expanded"); $(this).blur(); } );
And now an example of handling the following radio buttons:
<input type="radio" name="option_layout" value="0" checked="checked" /> <input type="radio" name="option_layout" value="1" />
And now the jQuery code for handling them:
$("input[@name='option_layout']").change( function() { if ($("input[@name='option_layout']:checked").val()) $(".group").toggleClass("group_vert"); else $(".group").toggleClass("group_vert"); $(this).blur(); } );
AKPC_IDS += "115,";
Tags: jquery
相关文章推荐
- [Drupal] Creating Checkboxes, Radio Buttons, or Select Lists
- Reading CheckBoxes and Radio Buttons
- jquery获取和设置radio,check,select选项(转)
- jquery获取和设置radio,check,select选项
- How To Setup And Check MO / MOAC Setups In a R12 APPS Instance - Precedence of MO / MOAC Profile Options [ID 745420.1]
- jquery获取和设置radio,check,select选项
- Limiting To Select Only 5 Check Boxes Out Of Ten In Oracle Forms
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- How to retrieve checkboxes values in jQuery
- jquery input text radio check select 操作(转)
- jQuery操作radio、checkbox、select总结(转载修改)
- Jquery 获取select,option,radio选中对象与值(不断更新中)
- <h1 class="title">jquery的checkbox,radio,select等方法总结</h1> <div class="meta"><time datetime="201
- Authorize attribute and jquery AJAX in asp.net MVC
- SharePoint Designer Check In and Check Out Error
- Checkbox - Jquery - Check All / Select All
- Code Review Checklist and Best practices in Java
- phpmyadmin错误:Cannot start session without errors, please check errors given in your PHP and/or we