Adding row in table in xhtml document with jQuery 1.4.4 and Firefox
I have to pass a web site from html to xhtml because in need to include svg.
Since this change, I can't add row in tables.
Environment : Firefox 3.6.12 with firebug, jQuery 1.4.4
Unit test:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).rea开发者_JAVA技巧dy(function(){
$("a.addrowb").click(function(){
$("table tbody").append("<tr><td>new row on bottom</td><td></td></tr>");
return false;
})
$("a.addrowt").click(function(){
$("table tbody").prepend("<tr><td>new row on top</td><td></td></tr>");
return false;
})
})
</script>
<title>Untitled Document</title>
</head>
<body>
<a class="addrowb" href="#">Add row In the bottom</a> <a class="addrowt" href="#">Add row In the Top</a>
<table border="1">
<tbody>
<tr>
<td>Text 1</td><td>text 2</td>
</tr>
</tbody>
</table>
</body>
</html>
You need to externalize your custom JS.
for example, create a main.js in the same folder you got your .xhtml file in and put your custom code in it :
$(document).ready(function(){
$("a.addrowb").click(function(){
$("table tbody").append("<tr><td>new row on bottom</td><td></td></tr>");
return false;
})
$("a.addrowt").click(function(){
$("table tbody").prepend("<tr><td>new row on top</td><td></td></tr>");
return false;
})
})
Then, in your xhtml, instead of
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("a.addrowb").click(function () {
$("table tbody").append("<tr><td>new row on bottom</td><td></td></tr>");
return false;
})
$("a.addrowt").click(function () {
$("table tbody").prepend("<tr><td>new row on top</td><td></td></tr>");
return false;
})
})
</script>
write
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="main.js"></script>
精彩评论