gridview文本框启用使用jQuery禁用

时间:2013-04-23 19:20:06

标签: jquery asp.net

我遇到了jQuery的问题。当我开始在txtiPercentage文本框中书写时,应仅为该特定行禁用txtDollarAmtinfo文本框。

<gridview ID="BulkEditGridView1" 
          runat="server" 
          AutoGenerateColumns="False" 
          DataKeyNames="Pk_PropertyID">    
  <Columns>
    <asp:TemplateField>
      <ItemTemplate>
        <asp:TextBox ID="txtiPercentage" 
                     Text='<%#Eval("BidPercentage","{0:0.000}") %>' 
                     runat="server" 
                     onKeyDown="OnKeyDownHandler(this,event)"></asp:TextBox>  
        <asp:TextBox ID="txtDollarAmtinfo" 
                     Text='<%#Eval("BidDollarAmt","{0:0,00}") %>' 
                     runat="server" ></asp:TextBox> 
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </gridview>

脚本:

<script type="text/javascript">
    function OnKeyDownHandler(thisobj,e) {
        var newid = $(thisobj).attr('id');
        $(thisobj).closest('tr')
          .find("input[id$="txtDollarAmtinfo"]:not(input[id$=' + newid + '])')
          .attr("disabled", "disabled")");           
     }
 </script>

3 个答案:

答案 0 :(得分:0)

删除asp内容中的OnKeyDown标记。使用jQuery

$("#<%= txtiPercentage.ClientID %>").keyup(function() {
    var newID = $(this).attr("id");

    //Either find it with .next
    $(this).next().prop("disabled", true);

    //Or disable by ID
    $("#<%=txtDollarAmtinfo.ClientID%>").prop("disabled", true);
});

不要忘记在脚本开头的$(document).ready() {中包含这个内容! :)

答案 1 :(得分:0)

希望这有帮助。

<script>
function lock_a_txt(sender)
{
    var who_to_lock = $(sender).attr('data-lockdown-id');
    //disable by sender data tag value in the scope of the senders row
    $('#' + who_to_lock, $(sender).parents('tr').first()).prop('disabled', true)
}
</script>

<table>
    <tr>
        <td>
            <asp:TextBox runat="server" ID="txtPercent" data-lockdown-id="txtDollar" onkeypress="javascript:lock_a_txt(this);" />
        </td>
        <td>
            <asp:TextBox runat="server" ID="txtDollar" />
        </td>
    </tr>
</table>

答案 2 :(得分:0)

您的报价不匹配。处理程序的结尾应如下所示:

    $(thisobj).closest('tr')
      .find('input[id$="txtDollarAmtinfo"]:not(input[id$="' + newid + '"])')
      .attr("disabled", "disabled");