JQuery对话框:在对话框中从文本框获取值不工作获得旧值

时间:2011-06-14 14:49:15

标签: jquery jquery-ui dialog

我有一个JQuery对话框,里面有一个包含文本框的控件,里面还有一个保存按钮。 在保存点击中,我从文本框中获取值并将其传递给函数。

问题:

每当我更改文本框中的值时,它只会获得旧值

所以,如果原始值为2,我将其更改为20,我单击按钮,它将获得值2.

任何人都有任何关于它为什么会这样做的想法?

谢谢!

这里有一些代码:

JQUERY:

  $("#inputupdatecontrol<%=PlantID %>").dialog({
            autoOpen: false,
        modal: true,
        width: 500,
        height: 400
    });

HTML:

<script type="text/javascript">
function SaveActivityManagementData() {

    var plantid = $('.drpplants').val();
    var worktype = $('.worktype').val();

    var startdate = $('.startdate').val();

    var enddate = $('.enddate').val();
    var planid = $('.planid').val();
    var mob = $('.mob').val();

    var assignedto = $("input[name=txtassignedtoid]").attr("value");
    var currentuserId = $("input[name=CurrentUserId]").attr("value");
    var clientId = $("input[name=ClientId]").attr("value");


    AjaxSaveActivityManagementData(plantid, worktype, startdate, enddate, planid, mob, assignedto, currentuserId,clientId);
    }

</script>


<table>
<tr>
    <td>Plant:</td>
    <td><asp:DropDownList ID="drpPlants" runat="server" DataValueField="Id" DataTextField="Name" CssClass="drpplants"></asp:DropDownList></td>
</tr>

<tr>
    <td>Work Order:</td>
    <td>
        <div>
            <asp:Label ID="lblExisiting" runat="server" Text="Existing"></asp:Label>
            <asp:RadioButton runat="server" GroupName="workorder" ID="rbExisting" Checked="true" />
            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
        </div>
        <div>
            <asp:Label ID="Label1" runat="server" Text="New"></asp:Label>
            <asp:RadioButton ID="rbNew" runat="server" GroupName="workorder" />
            <asp:TextBox ID="txtnew" runat="server"></asp:TextBox>
        </div>
    </td>
</tr>

<tr>
    <td>Work Type:</td>
    <td>
        <asp:DropDownList ID="DropDownList2" runat="server" CssClass="worktype">
            <asp:ListItem Text="non-routine"></asp:ListItem> 
            <asp:ListItem Text="pilot project"></asp:ListItem> 
            <asp:ListItem Text="routine"></asp:ListItem> 
        </asp:DropDownList>
   </td>
</tr>

<tr>
    <td>Description:</td>
    <td><asp:TextBox ID="txtDesc" runat="server"></asp:TextBox></td>
</tr>

<tr>
    <td>Start Date:</td>
    <td><asp:TextBox ID="txtStartDate" runat="server" CssClass="startdate"></asp:TextBox></td>
</tr>

<tr>
    <td>End Date:</td>
    <td><asp:TextBox ID="txtEndDate" runat="server" CssClass="enddate"></asp:TextBox></td>
</tr>

<tr>
    <td>Plan ID:</td>
    <td><asp:TextBox ID="txtPlanId" runat="server" CssClass="planid"></asp:TextBox></td>
</tr>

   <tr>
    <td>MOB:</td>
    <td><asp:TextBox ID="txtMOB" runat="server" CssClass="mob"></asp:TextBox></td>
</tr>

<tr>
    <td>Assigned To:</td>
    <td>
        <asp:TextBox ID="txtAssignedTo" runat="server" CssClass="assignedto"></asp:TextBox>
        <input type="text" name="txtassignedtoid" visible="false" class="assignedtoid" style="display:none;" />            
        <input type="text" name="CurrentUserId" visible="false" class="userid" style="display:none;"  />                  
        <input type="text" name="ClientId" visible="false" class="clientid" style="display:none;"  />                 
    </td>
</tr>

<tr>
    <td></td>
    <td><asp:CheckBox runat="server" ID="chkOverRide" Text="Override" /></td>
</tr>

<tr>
    <td></td>
    <td><asp:DropDownList ID="drpAssignment" runat="server" DataTextField="FirstName" DataValueField="id"></asp:DropDownList></td>
</tr>

<tfoot>
    <tr>
        <td></td>
        <td>
            <asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="SaveActivityManagementData();"/>
            <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="DeleteClick" />
            <asp:Button ID="btnCancel" CssClass="btnFormCancel" runat="server" Text="Cancel" />
        </td>
    </tr>
</tfoot>

1 个答案:

答案 0 :(得分:3)

我以前经历过这个 - 不是用jQuery而是用YUI。我相信.val()方法很容易在变更事件传播之前返回值 - 而直接访问底层DOM元素的值应该有效。所以而不是:

var plantid = $('.drpplants').val();

你有类似的东西:

var plantid = $('.drpplants').get(0).value;

您可能需要更正第二种语法 - 我不确定这是在jQuery中访问底层DOM节点的最佳方式......