0

支払いチェックボックスがチェックされている場合にのみ、支払い日を選択するための入力フィールドを有効にしたいです!チェックボックスをクリックすると、支払いの確認質問がトリガーされます。確認すると、チェックボックスがオンになり、入力ボックスが編集可能になります。動作していないコードは次のとおりです。

<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

4 に答える 4

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!" />');
        }
      }
于 2012-10-24T12:14:43.207 に答える
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>
于 2012-10-24T12:14:57.683 に答える
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/

于 2012-10-24T12:15:41.120 に答える
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')

于 2012-10-24T12:21:21.823 に答える