开发者

Can't access button in nested button control with jQuery

I'm trying to submit a form from JavaScript when a user hits the [ENTER] key. .submit won't work because we have multiple buttons in our form.

The DDLClientName drop down list resides in our aspnetForm form. There is another custom control in this form called SaveCancelDelete. This control (*.ascx) contains all of our buttons.

What I want to do is cause the click event to fire for one of the buttons. What I have below works, but it's a little hacked up. I tried the code below that with the nested ClientID callbacks, but that doesn't seem to work. I'm looking for the cleanest approach.

    jQuery(this.Elemen开发者_StackOverflow中文版ts.DDLClientName).keypress(function(e) {
        if (e.keyCode === 13) {
            //jQuery("#aspnetForm").submit();
            jQuery("#ctl00_body_QuickDataEntryEditor_SaveCancelDelete_BtnNonAuthenticated1").click();
        }
    });

This doesn't seem to work:

jQuery('#<%=SaveCancelDelete.ClientID %>').jQuery('#<%=BtnNonAuthenticated1.ClientID %>').click();


Your second example needs to be .find() instead of .jQuery()

jQuery('#<%=SaveCancelDelete.ClientID %>').find('#<%=BtnNonAuthenticated1.ClientID %>').click();

but since it's already an ID, you don't really need to have both, this should work too:

jQuery('#<%=BtnNonAuthenticated1.ClientID %>').click();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜