簡體   English   中英

jQuery的追加和HTML不運行,但刪除

[英]jquery append and html does not run but remove does

在下面的代碼中,我試圖在按鈕單擊上添加一個<tr>

任何幫助將不勝感激。

 $("#gtab").append("<tr><td width='34%'><textarea style='width:290px; height:100px'> At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. </textarea></td> <td width='33%'><textarea style='width:290px; height:100px'> At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. </textarea></td> <td width='33%'><input type='button' value='Del' onclick='$(this).parent().parent().remove();'></td></tr>"); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table width="100%" align="center" id="gt1" class="gtab"></table> <input type='button' value='Add' onclick='nr();'> 

您的ID是gt1所以請更改

$("#gtab")

$("#gt1")

nr()的實現在哪里? 我希望那條線在里面。

你這里有兩個問題

  1. 您沒有創建事件偵聽器來處理按鈕單擊操作。
  2. 您已使用class選擇對象,但改為使用#調用.

檢查下面的我的代碼段。

 function nr() { $(".gtab").append("<tr><td width='34%'><textarea style='width:290px; height:100px'> At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. </textarea></td> <td width='33%'><textarea style='width:290px; height:100px'> At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. </textarea></td> <td width='33%'><input type='button' value='Del' onclick='$(this).parent().parent().remove();'></td></tr>"); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table width="100%" align="center" id="gt1" class="gtab"></table> <input type='button' value='Add' onclick='nr();'> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM