代码之家  ›  专栏  ›  技术社区  ›  Mohammad Sepahvand

如何用jQuery检查asp.net文本框中的文本是否被选中?

  •  1
  • Mohammad Sepahvand  · 技术社区  · 14 年前

    我想知道这是否可能,我想检查用户是否在文本框控件中选择了文本,就像 this solution (但这只是针对html输入控件,而不是asp.net服务器控件)

    2 回复  |  直到 9 年前
        1
  •  2
  •   Adil    14 年前

    你需要 nothing to change 用于服务器控制 except the syntax 就这个例子而言。

    <asp:TextBox id="txt1" runat="server" value="Selected?"><asp:TextBox>
    
    <asp:Button id="btnSubmit" runat="server" OnClientClick="alert(isTextSelected();" ></asp:Button>
    
        function isTextSelected() {
    input = document.getElementById('<%= test.ClientID %>'))
            if (typeof input.selectionStart == "number") {
                return input.selectionStart == 0 && input.selectionEnd == input.value.length;
            } else if (typeof document.selection != "undefined") {
                input.focus();
                return document.selection.createRange().text == input.value;
            }
        }
    

        2
  •  0
  •   Josh Bedo    14 年前

    您只需使用

    $('select, input').click(function(){
       $(this).removeClass('disabled');
    });