开发者

Jquery file format

HI.

I have multiple webpages. So I have a common external js file. And I have added this js file to every page. I have multiple check boxes in every page. And I have written the click event in the external, common js file. But I wonder how the js file should be? Currently I have written like this.

$(document).ready(function() {
    $(".chk").click(function() {
    alert("hi");
   });
});

But whenever I click a checkbox the click event is fired twice. it should be once. I dont know where is the error, is there any error in writing the js file? pleas开发者_开发问答e comment.


It's unlikely that there is an issue with the jQuery include file and the code you've provided is correct and should work so I can't say for sure what the issue is.

When you have trouble identifying the source of a bug the best solution is to cut out various pieces of code until all you're left with is the most basic example of what you're trying to do. In this case a single page, with a single script tag containing the jquery code you've posted and a single checkbox with a class of chk. At some point between the code you have and this destination the bug will disappear and you can then zero in on that piece of code.


Is it possible you've included the external file twice, somehow? (Perhaps once manually and once using a build script).


change click into change.. u must be double clicking on checkbox

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜