简体   繁体   English

jQuery对话框的提交按钮不能控制启用/禁用

[英]jquery dialog submit button cannot control enable/disable

I've been battling with this issue all day. 我整天都在与这个问题作斗争。 I am hoping someone has an answer for me. 我希望有人能为我解答。 I did a bunch of searching and can't seem to find an answer. 我做了很多搜索,但似乎找不到答案。

I have a page that has 3 forms on it. 我的页面上有3种形式。 I am working within the 2nd form. 我正在第二种表格内工作。 None of the forms are embedded within another form. 没有一个窗体被嵌入另一个窗体中。

I have a hidden div that contains two form elements, a drop down list and a text box, and a submit button that I anticipated it posting to the form it is enclosed in. On another button within the form itself (not submit button), I have javascript that launches jquery.Dialog, that code looks like this: 我有一个隐藏的div,其中包含两个表单元素,一个下拉列表和一个文本框,以及一个提交按钮,我希望它可以将其发布到它所包含的表单中。在表单本身的另一个按钮上(不是提交按钮),我有启动jquery.Dialog的javascript,该代码如下所示:

function showReleaseDiv() {
    var div = $("#ReleaseHoldsDiv");
    var f = div.closest("form");
    div.dialog({ width: 270, height: 187, modal: true, title: 'Bulk Hold Resolution' });
    div.parent().appendTo(f);
}

This part does function correctly. 这部分功能正常。 I've overcome the typical jquery issue where it pulls the contents of the dialog out of the form, so I put it back in the form, but wonder if this is causing my real issues which are: 我已经克服了典型的jquery问题,该问题将对话框的内容从表单中拉出,因此我将其放回表单中,但是想知道这是否引起了我的真正问题:

The drop down list and text box are both required before I post, so I default the submit button to disabled, then I have an onchange event on the drop downlist, and the onkeyup on the text box call the following javascript: 张贴之前,下拉列表和文本框都是必需的,因此我默认将“提交”按钮设置为“已禁用”,然后下拉列表中有一个onchange事件,文本框上的onkeyup调用以下javascript:

function enablePopupRelease() {
    var button = $("PopupReleaseButton");
    if (button && button != null) {
        button.attr("disabled", "disabled");
        if ($("#ResolutionTypeCode").val() != "" && $("#ResolutionComments").val() != "") {
            button.removeAttr("disabled");
        }
    }
    return true;
}

Both events fire correctly and I step through the code; 这两个事件均正确触发,我逐步执行了代码; all seems fine, but the button disable state does not change. 一切似乎都很好,但是按钮禁用状态不会改变。

Please help. 请帮忙。

I believe you are missing a hash on this line: 我相信您在此行上缺少哈希:

Change: 更改:

var button = $("PopupReleaseButton");

to

var button = $("#PopupReleaseButton");

firstly I would clean some code as follows: 首先,我将清理一些代码,如下所示:

function enablePopupRelease() {     var button = $("PopupReleaseButton");     if (button) {         button.attr("disabled", "disabled");         if ($("#ResolutionTypeCode").val() && $("#ResolutionComments").val()) {             button.removeAttr("disabled");         }     }     return true; } 

Let me know if makes any difference please? 请让我知道有什么不同吗?

if you break through the code ... does it stop at button.removeAttr("disabled"); 如果您突破了代码……它会停在button.removeAttr(“ disabled”);吗? please? 请?

Are you using the jQuery UI button widget for the form's submit button? 您是否将jQuery UI按钮小部件用于表单的提交按钮? If so, you will need to call 如果是这样,您将需要致电

$("#PopupReleaseButton").button({disabled: true});

to disable the button. 禁用按钮。

disabled isn't an attribute, it's a property -- try using button.prop('disabled',true) and button.prop('disabled',false) instead. disabled不是属性,而是属性-尝试改用button.prop('disabled',true)button.prop('disabled',false)

http://api.jquery.com/prop/ http://api.jquery.com/prop/

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

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