【问题标题】:Clear Enabled textboxes in form using jquery使用 jquery 清除表单中启用的文本框
【发布时间】:2012-07-12 10:31:45
【问题描述】:

当设置为 read only = true 或 Enabled = false 时,我需要清除/重置文本框值。我在我的代码中使用了重置功能,但这不起作用。 我的代码为

function resetForm($form) {
    $form.find('input:text, input:password, input:file, select').val('');   
    $("input[type='hidden']", this).each(function () {
        this.value = '';
    });    
    $form.find('input:checkbox')
         .removeAttr('checked').removeAttr('selected');

}

 <asp:TextBox ID="txteventid" runat="server" ReadOnly="true"/>

任何建议..

【问题讨论】:

    标签: jquery asp.net textbox reset


    【解决方案1】:

    我不确定你的重置功能在做什么,因为我看不到read only 检查的if condition,但你可以试试这个::)

    即使用 API; .prop http://api.jquery.com/prop/ 并检查属性或属性的状态:

    希望这对您的目的有所帮助:)

    如果你喜欢:.prop() vs .attr()

    并且这可能会派上用场:Select elements by attribute

      function resetForm($form) {
        $form.find('input:text, input:password, input:file, select').val('');   
        $("input[type='hidden']", this).each(function () {
            if($(this).prop('readonly')){ // you could check with string i.e. $(this).prop('readonly') === "true"
             this.value = '';
            }
        });    
        $form.find('input:checkbox')
             .removeAttr('checked').removeAttr('selected');
    
    }
    
     <asp:TextBox ID="txteventid" runat="server" ReadOnly="true"/>
    

    【讨论】:

    • 不,它不工作,你能告诉 this.prop('readonly') 指定文本框吗??
    • 嘿@kk1076 你能弹一下演示吗?很难发现什么不起作用,:) 对此提出警告alert($('#txteventid').prop('ReadOnly')); 让我知道你会得到什么回报,我们会解决的,不用担心
    • 很好。如上所述,警报显示为未定义。我尝试作为 dis if $('MainContent_uscEventParameters_txteventid').prop('ReadOnly')) { document.getElementById("'MainContent_uscEventParameters_txtevent").value = ""; } 但它没有清除值。
    • @kk1076 很酷,所以它不会注册你上面提到的元素,你能做一个演示/jsfiddle 如果你能在演示中复制它,我可以更好地帮助你,干杯:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多