启用输入字段确认返回

时间:2012-10-24 12:11:31

标签: jquery html

我想启用一个输入字段,仅当选中了付款复选框时才会选择付款日期!点击复选框会触发付款确认问题,如果确认,则选中复选框,输入框将可编辑! 这是不起作用的代码:

<script type="text/javascript">
  $(document).ready(function(){
    $("#talk").click(function(){
       return confirm("Did you pay the tax?");
      var isChecked = $('#talk').is(':checked');
      if(isChecked==true)
      {

        $("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" />');
      }
    });
  });
</script>

<div id="paydate">
<input type="checkbox" id="talk" />
<input type="text" id="name" readonly />
</div>

感谢您的帮助!

4 个答案:

答案 0 :(得分:0)

试试这个:

if(isChecked==true)
      {
        var a = confirm("Did you pay the tax?");
        if(a == true){
          $("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" />');
        }
      }

答案 1 :(得分:0)

将您的代码更改为以下

<script type="text/javascript">
  $(document).ready(function(){
    $("#talk").click(function(){
      var isChecked = $('#talk').is(':checked');
      if(isChecked==true)
      {
       if(confirm("Did you pay the tax?"))
        $("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" 

/>');
      }
    });
  });
</script>

<div id="paydate">
<input type="checkbox" id="talk" />
<input type="text" id="name" readonly />
</div>

答案 2 :(得分:0)

  $(document).ready(function(){
    $("#talk").click(function(){
      var isChecked = $('#talk').is(':checked');

      if(isChecked==true)
      {
        if(confirm("Did you pay the tax?"))
        $("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" />');
      }
    });
  });

示例:http://jsfiddle.net/EH6CG/

答案 3 :(得分:0)

无需重新创建元素 只需删除readonly属性:

$("#talk").click(function() {
    var isChecked = $('#talk').is(':checked');
    if (isChecked == true) {
        if (confirm("Did you pay the tax?")) {
            $('#name').removeAttr('readonly')
        }
    }
});

要锁定复选框,请在评论后在$(this).prop('disabled',true)

之后添加$('#name').removeAttr('readonly')
相关问题