jQuery适用于jsFiddle不适用于wesite [英] jQuery works on jsFiddle doesn't work on wesite

查看:115
本文介绍了jQuery适用于jsFiddle不适用于wesite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可在jsFiddle中使用的jQuery脚本,但在实际的网站上却无法使用,而且我想不出其他办法.

I have a jQuery script that works in jsFiddle, but doesn't work on an actual website and I cannot think of anything more to do.

这是小提琴

,这是网站

我需要一个复选框,当单击该复选框时,它将依次检查许多其他复选框.

I need a checkbox that when clicked will in turn check a number of other checkboxes.

$("form input[id='selectall']").click(function () {
    var inputs = $("form input[class='produse4export']");
    for (var i = 0; i < inputs.length; i++) {
        if (this.checked) {
            inputs[i].checked = true;
            checkme();
        } else {
            inputs[i].checked = false;
            uncheckme();
        }
    }
});

选中(同时全部)这些复选框时,它们必须启用其他复选框.取消选中它们后,其余复选框必须再次禁用和取消选中(如果已选中).

When these checkboxes are checked (all at once), they have to enable other checkboxes. When they are unchecked the rest of the checkboxes have to be again disabled and unchecked (if they were checked).

Kinda很难解释,但是小提琴和网页都很容易阅读.为什么它不能按预期工作?

Kinda hard to explain, but both the fiddle and the webpage are easy to read. Why doesn't it work as expected?

推荐答案

在小提琴中,您是在页面加载时绑定事件.在页面上,您尝试在解析页面本身时执行此操作.

In the fiddle, you are binding the event on page load. On your page, you are attempting to do it while parsing the page itself.

在您的页面上,将事件处理程序绑定代码更改为:

On you page, change the event handler binding code to:

$(document).ready(function() {
    $("form input[id='selectall']").click(function () {
        ...
    });
});

这篇关于jQuery适用于jsFiddle不适用于wesite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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