简体   繁体   English

在复选框中未选中的jQuery中重置文本框值

[英]On checkbox unchecked reset textbox value in Jquery

On selecting File below checkbox gets enabled if checkbox is checked then the below password textbox gets enabled. 在选择文件下方复选框时,如果复选框被选中,则启用以下密码文本框。

此搜索

If the checkbox is unchecked the password textbox gets hide but the textbox value is not getting cleared. 如果未选中该复选框,则密码文本框将被隐藏,但文本框的值不会被清除。

镜像2

$(function() {
  $('#<%=chkAddPdfPassword.ClientID %>').ready(
    function() {
      $('#<%=chkAddPdfPassword.ClientID%>').click(function() {
        if ($('#<%=chkAddPdfPassword.ClientID%>').is(":checked")) {
          $("#divPasswordField").show();
        } else {
          $(document).ready(function() {
            $('#txtFilePassword').val('');
          });
          $("#divPasswordField").hide();
        }
      })
    })
})

How can we do this with jQuery. 我们如何使用jQuery做到这一点。

Try removing the $(document).ready() 尝试删除$(document).ready()

  $(function () {
        $('#<%=chkAddPdfPassword.ClientID %>').ready(
        function () { 
            $('#<%=chkAddPdfPassword.ClientID%>').click(function () {
                if ($('#<%=chkAddPdfPassword.ClientID%>').is(":checked")) {  
                    $("#divPasswordField").show();
                } else {            
                    $('#txtFilePassword').val('');
                    $("#divPasswordField").hide();
                }
            })
        })
    })

Issue resolved : Solution 问题已解决:解决方案

 <script> 
    $(function () {
        $('#<%=chkAddPdfPassword.ClientID %>').ready(
        function () { 
            $('#<%=chkAddPdfPassword.ClientID%>').click(function () {
                if ($('#<%=chkAddPdfPassword.ClientID%>').is(":checked")) {  
                    $("#divPasswordField").show();
                } else {
                    $("#divPasswordField").hide(); 
                     document.getElementById('<%= txtFilePassword.ClientID %>').value = '';
                } 
            })
        })
    }) 
</script> 

Answer 回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM