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();
}
);

Tags: jquery

欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!http://www.cnblogs.com/sunshine-anycall/archive/2010/07/01/1769103.html

时间: 2024-08-18 02:14:36

Handling Checkboxes, Radio Buttons and Select Options in jQuery [转]的相关文章

ASP.NET 2.0数据教程之五十一:为GridView控件添加Radio Buttons列

返回"ASP.NET 2.0数据教程目录" 第51到53章为优化GridView系列 导言: GridView控件提供了大 量的内置功能.它包含了一系列的域(field)来显示诸如text.images. hyperlinks和buttons.另外它支持模板(template)用于用户自定义界面.我们 可以构建这样一个GridView控件,用户仅需要点击控件里的一个按钮,每一条记 录行都可以选择.编辑.删除.除了控件本身内置的功能外,在某些情况下,我 们添加一些额外的.控件没有内置的功

android-在sdk中如何使用radio buttons解除AlertDialog?

问题描述 在sdk中如何使用radio buttons解除AlertDialog? 我创建了一个alertdialog,里面有俩个radio buttons,当用户选择一个选项时,我需要解除alertdialog,但是不知道怎么解除,请大家的帮忙. final CharSequence[] items = {""First Option""Second Option""}; AlertDialog.Builder builder = new Al

JQuery SELECT单选模拟jQuery.select.js_jquery

基于jQuery JavaScript Library v1.3.2 的单选模拟 (本文件是跟据 zhangjingwei 的Jquery Select(单选) 模拟插件 V1.3.4 修改而来的) a. 修改的主要原因是,原来的zhangjingwei的模拟在显示方式上的问题.在跟文字交替出现时会出现错位.现将模拟DIV的display修改为inline方式.更自然的嵌入到文本行中. b.在加载文件后自动转化样式名为'commonselect' 的select.简化调用 c.对select的o

html 设置Select options值进行绑定

<select id="cdms"> <option value="">请选择...</option> <option value="0x00">高频整流</option> <option value="0x01">恒流限压充电</option> <option value="0x02">恒压限流充电</o

可用性web表单的设计开发指南

可用性web表单的设计开发指南.表单在web设计中引发的讨论已经持续了10年,本文中罗列了多条原则,包括布局,验证,代码可读性,使用jquery来改良表单等. Two-Column vs. One This decision will generally depend on the content of the form, but it's often preferable to avoid a two-column layout if the form is fairly simple. Be

DPC:Creating a DataBound List of Radio Buttons--PA

-------------------------------------------------------------------------------- For More Information on ASP.NET This article examines how to create a databound listbox using ASP.NET. For more information on ASP.NET be sure to check out the articles

DPC:Creating a DataBound List of Radio Buttons--PART1[等级:中]

Creating a DataBound List of Radio Buttons -------------------------------------------------------------------------------- For More Information on ASP.NET This article examines how to create a databound listbox using ASP.NET. For more information on

jQuery Validate验证框架详解

版本信息: /*! * jQuery Validation Plugin v1.14.0 * * http://jqueryvalidation.org/ * * Copyright (c) 2015 Jörn Zaefferer * Released under the MIT license */   一.导入js库 <script type="text/javascript" src="validate/jquery-1.6.2.min.js">&

jQuery validate验证插件用法详解

一.可选项( options ) [1]  debug      类型:Boolean    默认:false 说明:开启调试模式.如果为true,表单不会提交,而且会在控制台显示一些错误消息(需要Firebug或者Firebug lite).当要阻止表单默认提交事件,尝试去开启它. Js代码 $(".selector").validate({    debug: true }) [2]  submitHandler      类型:Callback    默认:default (na