[英]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()
的實現在哪里? 我希望那條線在里面。
你這里有兩個問題
#
調用.
檢查下面的我的代碼段。
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.