1

我在使用 jQuery 时遇到问题。当我开始在txtiPercentagetextbox 中写作时,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>
4

3 回答 3

0

去掉OnKeyDownasp 内容中的标记。使用 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() {在脚本开头的 a 中!:)

于 2013-04-23T19:30:25.367 回答
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>
于 2013-04-23T19:56:30.467 回答
0

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

    $(thisobj).closest('tr')
      .find('input[id$="txtDollarAmtinfo"]:not(input[id$="' + newid + '"])')
      .attr("disabled", "disabled"); 
于 2013-04-23T21:48:52.200 回答