2015-01-02 79 views
0

您好我无法将按钮追加到动态创建的table.I知道这是一个简单的问题,但我试着查看引入的逗号和连接运算符,但无法得到结果。无法将按钮追加到jquery

$("#myTable").append("<tr id="+staticI+"><td>"+localStorage.getItem(staticI+" a")+"</td> <td>"+localStorage.getItem(staticI+" b")+"</td><td>"+localStorage.getItem(staticI+" c")+"</td><td><button type="button">D</button>"+"</td></tr>"); 

铬会抛出各种错误,如未定义按钮或意外标识符。请帮助。谢谢。

+2

您正在添加'type =“按钮”'。尝试'type ='button'',因为你正在用'''开始字符串,所以另一个'''会结束它。 –

+1

谢谢Rahul.It工作。 –

回答

1

包装在button上的"被误解为variable,即undefined。您可以用'包装它以避免错误。

尝试这样

$("#myTable").append(........"</td><td><button type='button'>D</button>".......); 

编辑:

哎呀没注意到的问题是在评论部分解决。

1

试试这个:

$("#myTable").append('<tr id="+staticI+"><td>'+localStorage.getItem(staticI+" a")+'</td> <td>'+localStorage.getItem(staticI+" b")+'</td><td>'+localStorage.getItem(staticI+" c")+'</td><td><button type="button">D</button></td></tr>'); 

你必须使用"<tr id="+staticI+">...代替你可以使用'<tr id="+staticI+">

我希望这个帮你一个错误。