使用jQuery或Ajax显示或隐藏字段 [英] Show or hide a field using jQuery or Ajax

查看:437
本文介绍了使用jQuery或Ajax显示或隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jQuery的新手,我想知道如何在复选框上单击(选择)后在表单上显示日期字段,并在取消选择后将其隐藏.下面是屏幕截图. -谢谢.

I am new to jQuery and I want to know how to show the date field on a form after a click(select) on the check box and hide it after unselecting it. Below is the screenshot. - Thank you.

推荐答案

HTML

<label for="chkEle">Check This</label>
<input type="checkbox" name="chkEle" />
<div id="divEle" style="display:none;"><date stuff></div>

JS

$("input[name=chkEle]").change(function(e) {
    $("#divEle").toggle();
});

即使单击标签而不是复选框,也会触发

.change.这也使您可以在以后动态地对js进行更改.例如,如果您想在页面加载时强制选中复选框,那么在代码结尾,您可以添加$("input[name=chkEle]").change();,这将在后端和视觉上触发更改

.change is triggered even if the label is clicked instead of the checkbox. This also allows you to dynamically make change in js later. For instance if you wanted to force the checkbox selection on page load, then at the end of you code you could add $("input[name=chkEle]").change(); and that would trigger the change both on the back end and visually

这篇关于使用jQuery或Ajax显示或隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆