在复选框上显示jQuery textarea [英] show jQuery textarea on checkbox tick

查看:71
本文介绍了在复选框上显示jQuery textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我取消勾当后为什么我的代码没有隐藏的问题上,我处于松懈的态度.如果有人可以检查我的代码并指出我要去哪里,我将不胜感激.我已经在 此处 中发布了代码.非常感谢

I am at a loose end as to why my code is not hiding when i untick. I would be grateful if someone could check my code and point out where I am going wrong. I have posted code here. many thanks

推荐答案

您可以使用this.checked

$('input[name=messagetick]').click(function() {
    if (this.checked) {
        $('.contactmessage').show();
    }
    else {
        $('.contactmessage').hide();
    }
});

稍好一点的版本将使用.toggle([showOrHide])

A slightly better version would use .toggle([showOrHide])

$('input[name="messagetick"]').click(function() {
    $('.contactmessage').toggle(this.checked);
});

旁注,使用属性选择器时请不要忘记".

Side note, don't forget your " when using an attribute selector.

关于jsfiddle的示例

Example on jsfiddle

这篇关于在复选框上显示jQuery textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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