是:使用Jquery 1.7时检查不起作用 [英] is :checked not working while using Jquery 1.7

查看:70
本文介绍了是:使用Jquery 1.7时检查不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个简单的代码

html

<input type="checkbox" id="check" >&nbsp;<span id="rm">Remember
me</span> <span id="ok">Okay!</span>

css

#ok{
position:absolute;
font:italic bold 14px century;
color:green;
margin-left:3px;
margin-top:2px;
display:inline-block;
opacity:0;
}

Jquery

if($('#check').is(":checked"))
    {
    $("#ok").css("opacity",1);
    }

http://jsfiddle.net/milanshah93/4Hf9T/

我选中此框时无法正常工作。

It is not working when I check the box.

推荐答案

您的复选框未在页面加载时选中。虽然你可以这样做 -

Your checkbox was not checked on page load. although you can do something like this -

$("#check").on('change', function () {
    if ($(this).is(":checked")) {
        $("#ok").css("opacity", 1);
    }
    else{
     $("#ok").css("opacity", 0);
    }
});

DEMO

这篇关于是:使用Jquery 1.7时检查不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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