JavaScript 标签 + IE 中的复选框点击问题,用图像替换复选框
我的表单存在问题:
http://lexusevents.sanscode.com/datawash/details/pagetwo/1a08c087bdd3f0f85359a2a2e61ca74a
基本上你所拥有的是一堆 的坐姿在带有这样的复选框的标签内:
<label for="mybox">
<input type="checkbox" id="mybox">
<img src="">
</label>
当您在 Firefox 或 Chrome 中单击图像时,标签会触发复选框和我巧妙的 CSS 样式会更改图像,让一些文本位于顶部,表明它已被选中。
现在的问题是,当我在 IE 中时,标签单击不起作用。它不会触发复选框。因此,在完全不知道为什么我决定应该尝试使用 jquery 来修复它的情况下。
if ($.browser.msie) {
$('.checkbox label').bind('click', function() {
checkbx = $(this).children('input');
me = $(this);
checkbx.click();
if (checkbx.is(':checked')) me.addClass('checked');
else me.removeClass('checked');
});
$('.checkbox label').each(function() {
var c = $('input', this);
var me = $(this);
if (c.is(':checked')) me.addClass('checked');
else me.removeClass('checked');
});
}
此代码在以 checkbx = $(th
开头的行上有一个错误...显然有一个属性不支持此方法错误,但我不知道为什么。
任何人都可以帮忙我在这儿吗?
Having an issue on my form here:
http://lexusevents.sanscode.com/datawash/details/pagetwo/1a08c087bdd3f0f85359a2a2e61ca74a
Basically what you have there is a bunch of <img>
's sitting inside a label with a checkbox like this:
<label for="mybox">
<input type="checkbox" id="mybox">
<img src="">
</label>
When you click the image in firefox or chrome, the label fires the checkbox and my crafty CSS styles change the image to have some text sit on top indicating it is selected.
Now the issue is that when i'm in IE, the label click doesn't work. It won't fire the checkbox. So without fully knowing why I decided I should try to use jquery to fix it.
if ($.browser.msie) {
$('.checkbox label').bind('click', function() {
checkbx = $(this).children('input');
me = $(this);
checkbx.click();
if (checkbx.is(':checked')) me.addClass('checked');
else me.removeClass('checked');
});
$('.checkbox label').each(function() {
var c = $('input', this);
var me = $(this);
if (c.is(':checked')) me.addClass('checked');
else me.removeClass('checked');
});
}
This code has an error on the line that starts with checkbx = $(th
... apparently there is a property doesn't support this method error but i can't work out why.
Can anybody help me out here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于表单中的其他输入造成的:
根据您的 html,您还具有此标记:
这可能会导致 IE 出现问题。您可能想要更改查询:
从:
到(很可能是这样,或者在查询中更具体以仅选择复选框的输入类型):
This might due to the other input in your form:
As per your html, you also had this tag:
That might cause an issue in IE. You might want to change your query:
From:
To (Most likely like this or be more specific in the query to select only input type of checkbox):