2016-12-27 6 views
0

テキストボックスとラジオボタンを含むテーブル(テーブル行ではない)を複製したいとします。jqueryのクローン作成中にラジオボタンの値が削除される

具体的には、テキストボックス値なしでラジオボタン値を使用してテーブル全体をクローンしたいとします。

ここで、テキストボックスとラジオボタンの値は、複製中に削除されます。どのようにして目的の行動を得ることができますか?クローニングながらのそれはunchecですので

<script> 
 
$("#tablePreviousHistory").clone(true).attr('id', 'tablePreviousHistory' + k).find("input").val('').each(function() { 
 
       if (this.type=='radio') { 
 
        this.checked = false; 
 
       } 
 
       $(this).attr({ 
 
        'id': function (_, id) { return id + k }, 
 
        'name': function (_, name) { return name + k } 
 
       }); 
 
      }).end().insertAfter("#tablePreviousHistory" + (k != 1 ? (k - 1).toString() : '')); 
 
</script>

答えて

0

それは次のとおりです。

<div> 
 
<table id="tablePreviousHistory"> 
 
    <tbody> 
 
     <tr> 
 
      <td> 
 
       <input id="pCountry" name="pCountry" value="" type="text"> 
 
      </td> 
 
      <td> 
 
       <input id="pvisatype" name="pvisatype" value="" type="text"> 
 
      </td> 
 
      <td> 
 
       <input id="pstartdate" name="pstartdate" value="" type="text"> 
 
      </td> 
 
      <td> 
 
       <input id="pStatus" name="pStatus" value="Yes" type="radio"> 
 
       Yes<br> 
 
       <input id="pStatus" name="pStatus" value="No" type="radio"> 
 
       No 
 
      </td> 
 
     </tr> 
 
    </tbody> 
 
</table> 
 
</div>

Javascriptを:

ここ

は、私のコードですあなたは下のこの1とその行を交換する場合、

if (this.type=='radio') { 
     this.checked = false; 
} 
+0

こんにちは、 お返事ありがとうございます。 –

+0

こんにちは、 ご返信ありがとうございます。 私はあなたの提案に従って行を削除してみましたが、まだ動作していません!! –

0

入力はこのコード行でクリアされているテキスト

$("#tablePreviousHistory").clone(true).attr('id', 'tablePreviousHistory' + k).find("input").val('').each(function() { 

val('')と、次のようで、彼らはもはや必要があります明らかヒツジシラミバエ。

$("#tablePreviousHistory").clone(true).attr('id', 'tablePreviousHistory' + k).find("input").each(function() { 
+0

こんにちは、 返信いただきありがとうございます。 –

+0

こんにちは、 ご返信ありがとうございます。 私はあなたの提案に従って試しましたが、まだ動作していません!! –

関連する問題