javascript 函数第二次不工作

标签 javascript html jsp struts2

我使用下面的javascript函数来启用和禁用单选按钮文本框作为下拉列表的值 发生变化。
启动时没问题,但当我单击提交按钮时,如果在提交时 myindex = 8 或 9 则不起作用。
此时,单选按钮过滤器[0]和过滤器[1]应禁用,文本字段计数应启用我在选择下拉菜单和单击提交时调用此函数按钮。
我不知道为什么它不起作用。任何帮助。

function OnChange(dropdown) {
    var myindex = dropdown.selectedIndex;

    document.form.filter[0].disabled = false;
    document.form.filter[1].disabled = false;

    if (myindex == 8) {
        document.form.filter[0].disabled = true;
        document.form.filter[1].disabled = true;
        document.form.count.disabled = false;
        document.form.submit.disabled = false;
    } else if (myindex == 9) {
        alert("in ALL");
        document.form.filter[0].disabled = true;
        document.form.filter[1].disabled = true;
        document.form.count.disabled = true;
        document.form.submit.disabled = false;

        alert(document.form.filter[0].disabled);
    }

    else {
        document.form.filter[0].disabled = false;
        document.form.filter[1].disabled = false;
        document.form.count.disabled = true;
        document.form.submit.disabled = false;
    }
}

下面是我的 HTML 代码。

<s:form action="crInquiry" name="form" >
    <table align="center" width="1020">
        <tr>
            <td>Batch Id : <s:property value="batchId" />
                <fieldset
                    style="background-color: #F7F9F3; margin: 2px; padding: 8px; -moz-border-radius: 5pt; border: 1px solid #A7CBE3;">
                    <legend class="field_label">
                        <strong>Inquiry Log Status</strong>
                    </legend>
                    <table border="0" id="main_table1" cellpadding="5" width="1010"
                        cellspacing="5" align="center">
                        <tr style="height: 5px;">
                            <td width="300" height="2" align="left" colspan="0"><s:hidden
                                    name="batchId" id="batchId"
                                    onfocus="OnChange((this.form.filterValue));"
                                    value="%{ batchId }"></s:hidden> <s:select
                                    cssClass="bulkSelect" name="filterValue"
                                    label="Search Criteria" required="true" theme="css_xhtml"
                                    labelposition="bottom" tabindex="2" list="headerList"
                                    onchange="OnChange(this.form.filterValue);" />
                            </td>


                            <td width="180"><s:radio name="filter"
                                    requiredposition="right"
                                    list="#{'STATUS_FILTER_START':'START','STATUS_FILTER_END':'END'}"
                                    label="Stage" labelposition="right" theme="css_xhtml"
                                    tabindex="9" labelposition="bottom"></s:radio>
                            </td>
                            <td width="50" height="2"><s:textfield disabled="true"
                                    value="0" name="count" size="2" labelposition="1"
                                    theme="css_xhtml"></s:textfield>
                            </td>
                            <td width="180"><s:radio name="order"
                                    requiredposition="right" list="#{'ASC':'ASC','DESC':'DESC'}"
                                    label="Order" labelposition="right" theme="css_xhtml"
                                    tabindex="9" labelposition="bottom"></s:radio>
                            </td>
                            </td>


                            <td width="50"><s:submit theme="css_xhtml" value="Filter"
                                    align="left" onclick="gotopage('FilteredInquiryLog');"></s:submit>
                            </td>
                            <td width="59"><s:submit theme="css_xhtml" value="Details"
                                    onclick="gotopage('crInquiry')"></s:submit></td>

                        </tr>


                    </table>
                </fieldset>
            </td>
        </tr>

    </table>
</s:form>

并从提交中调用 js 函数,从它调用上面的 js 函数的地方

function gotopage(actionname) { 
        document.form.action = actionname + ".action";
        document.form.submit();
        OnChange(document.form.filterValue);

    }

最佳答案

您提交表单然后尝试操作字段似乎很奇怪......

function gotopage(actionname) { 
        document.form.action = actionname + ".action";
        document.form.submit();
        OnChange(document.form.filterValue);

    }

也许你需要的是:

function gotopage(actionname) { 
        OnChange(document.form.filterValue);

        document.form.action = actionname + ".action";
        document.form.submit();
    }

关于javascript 函数第二次不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9883640/

相关文章:

javascript - 使用jquery在javascript变量中复制html div

java - Spring MVC - 在 DispatcherServlet 中未找到带有 URI [/demo/test] 且名称为 'appServlet' 的 HTTP 请求的映射

javascript - jsp中的动态重力列表

javascript - 数据表计算总负载

jquery - Iframe 调整大小 CORS

JSP 自定义标记库与 JSP2 标记文件

javascript - 每当对象内容发生更改时,Angular 就会触发 EventEmitter

javascript - 如何根据某些条件减少文字对象?

javascript - 无法在 Safari 中使用 javascript 更改网站图标

javascript - 从 D3 颜色范围返回单个值以创建图例