简体   繁体   English

找不到点击事件

[英]Unable to find click event

Here is my JQuery Code: 这是我的JQuery代码:

$(function () {
$('[id*=clickbtn]').click(function () {
    var url = "WindowPages/EditorControl.aspx?controlName=" + this.name;
            oWnd.setUrl(url);
            oWnd.show();

        });

});

Now the problem is, i have 4 to 5 buttons whose id contains 'clickbtn' when i click the any one of them for first time it works well. 现在的问题是,当我第一次单击其中任何一个按钮时,我有4到5个按钮的ID包含“ clickbtn”。 But it does not works for second click, any help why is this happening? 但这不适用于第二次点击,这有什么帮助吗?

[EDIT]: [编辑]:

I tried putting the JQuery on page and it worked.. But wnt to know why it does not work on when i put the same on .JS file? 我尝试将JQuery放在页面上,并且可以工作。.但是,我想知道为什么当我将JQuery放在.JS文件上时,为什么它不起作用?

Yes, the result of your event handlers depends very much on the content of your event handlers. 是的,事件处理程序的结果在很大程度上取决于事件处理程序的内容。 If you'd like to share with us the rest of the code we might be able to help. 如果您想与我们分享其余的代码,我们也许可以提供帮助。 For now the answer is: working as intended 现在的答案是: 按预期工作

jsFiddle jsFiddle

If your clicks only work on the first try, then I can assure you that it is only the missing code which is to blame. 如果您的点击仅在第一次尝试时有效,那么我可以向您保证,只有丢失的代码才是应该引起的。 Provide the contents of oWnd.setUrl and oWnd.show and we might be able to help. 提供oWnd.setUrloWnd.show的内容,我们可能会提供帮助。

Your wildcard selector is wrong. 您的通配符选择器错误。 It should be 它应该是

$("[id$=clickbtn]")

Try this: 尝试这个:

$('input[ID*="Button"]')


OR 要么

First set class="btn" to all buttons you want to do this action then 首先将class =“ btn”设置为要执行此操作的所有按钮,然后

$(function() {
        $('.btn').click(function() {
        var url = "WindowPages/EditorControl.aspx?controlName=" + this.name;
        oWnd.setUrl(url);
        oWnd.show();
        });
    }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM