jQuery选中复选框IE问题 [英] jquery checked checkbox IE problem

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

问题描述

我在验证是否使用Internet Explorer上的jquery选中复选框时遇到问题. 这是我正在使用的代码:

I'm having an issue verifying if a checkbox is checked using jquery on Internet Explorer. This is the code I'm using:

if ($('#chkjq_1').attr('checked') == true)

在Firefox或Chrome上正常运行,但是在Internet Explorer 7上,该条件始终为false,因为浏览器通过以下方式设置属性:

It works fine on Firefox or Chrome, but on Internet Explorer 7, the condition is always false because the browser sets the property this way:

<input id="chkjq_1" type="checkbox" CHECKED/> IE7

正确的方法如下:(Firefox,Chrome):

And the right way is the following: (Firefox, Chrome):

<input id="chkjq_1" type="checkbox" checked="checked"/> FF, Chrome, etc

我应该怎么做才能避免在Internet Explorer 7上出现此问题; jQuery中有通用的方法可以解决这个问题吗?

What should I do to avoid this issue on Internet Explorer 7; is there a generic way in jquery to solve this?

谢谢.

推荐答案

尝试一下:

if ($('#chkjq_1').is(':checked'))
{
  // more code
}

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

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