博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Handling Checkboxes, Radio Buttons and Select Options in jQuery [转]
阅读量:6941 次
发布时间:2019-06-27

本文共 1683 字,大约阅读时间需要 5 分钟。

Handling Checkboxes, Radio Buttons and Select Options in jQuery

I figured I’d share how I’ve dealt with some form elements in . 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:

转载地址:http://ssinl.baihongyu.com/

你可能感兴趣的文章
spring自己主动装配Bean属性
查看>>
面对苦难请勇敢
查看>>
安全加固总论
查看>>
消息中间件概述
查看>>
008_线上排障汇总
查看>>
HRMS(人力资源管理系统)-从单机应用到SaaS应用-架构分析(功能性、非功能性、关键约束)-下篇...
查看>>
EF Core 2.1 中的 Eager loading、Explicit loading和LazyLoading (转自MSDN)
查看>>
C# http 性能优化500毫秒到 60 毫秒
查看>>
利用WPF创建含多种交互特性的无边框窗体
查看>>
unitywebrequest-post-url-jsondata
查看>>
【JAVA笔记】JAVA后端实现统一扫码支付:微信篇
查看>>
当你输入一个网址的时候,实际会发生什么?(转载)
查看>>
vc通过webbrowser操作ie元素
查看>>
JavaScript中RegExp.$1是什么意思
查看>>
Python中HTTPS连接
查看>>
基于epoll的简单的httpserver
查看>>
[Java] 简化正则表达式的使用
查看>>
关于echarts的那些事(地图标点,折线图,饼图)
查看>>
ExecutorService 的理解与使用
查看>>
[Javascript Crocks] Flatten Nested Maybes with `chain`
查看>>