jquery向 指定位置添加行的问题.急急急急急急!

liangphp 2011-07-26 06:22:29
jquery

function addnewRows()
{
var idhidden=$("#idhidden").val();
var id=parseInt(idhidden);
var postid=id+1;
$("#idhidden").val(postid);

$.post("addnewRows.php",{newId:postid},function(data){

$("#a_div").append(data);//返回的是“<tr><td>fuck the world</td></tr>”
})
}

html
<table>
<tr><td>hello world</td><tr>//我想在下面两个tr之间显示jquery返回的值,所以就加了个div,可这样不行啊
<div id="a_div"></div>//加在俩个tr之间就不好用了
<tr><td><input type="hidden" id="idhidden" value='1'><input type='button' onclick="addnewRows"></td></tr>
</table>


前辈们如何在那两行直接接收返回的值啊.....请帮忙看看...小弟万分感谢
...全文
343 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
guotongyu1 2011-07-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liangphp 的回复:]

引用 4 楼 lsw645645645 的回复:
HTML code

<!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/x……
[/Quote]
减法
liangphp 2011-07-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lsw645645645 的回复:]
HTML code

<!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>
<title>……
[/Quote]

前辈啊,我再问个简单的小问题哈

我现在有一行
产品名称 金额
<span>牙膏</span> <span> 20</span> 总金额为20
我又添加了一行
<span>牙刷</span> <span> 15</span> 总金额变成35
可是现在我又想把刚刚添加的那行删除了,我就用的您的教给我的这个方法,可是删除后总金额还是35,应该变成20的啊,请问一下这在js或者jquery中要怎么运算啊...





lsw645645645 2011-07-26
  • 打赏
  • 举报
回复

<!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>
<title></title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">

function addnewRows() {
$("table tr").eq(0).after('<tr><td>fuck the world</td></tr>');
}
function removenewRows() {
$("table tr").eq(1).remove();
}
</script>

</head>
<body>
<table>
<tr><td>hello world</td></tr>

<tr><td><input type='button' value="添加" onclick="addnewRows()"><input type='button' value="删除" onclick="removenewRows()"></td></tr>
</table>

</body>
</html>



liangphp 2011-07-26
  • 打赏
  • 举报
回复
非常感谢....
我追加一个问题哈,那删除指定的一行呢?????...
比方说一共有四行,我只想把第三行删了啊
lsw645645645 2011-07-26
  • 打赏
  • 举报
回复

<!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>
<title></title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">

function addnewRows() {
$("table tr").eq(0).after('<tr><td>fuck the world</td></tr>');
alert($("table").html());
}
</script>

</head>
<body>
<table>
<tr><td>hello world</td></tr>

<tr><td><input type='button' value="Btn" onclick="addnewRows()"></td></tr>
</table>

</body>
</html>


hongmei85 2011-07-26
  • 打赏
  • 举报
回复
这样可以?
<table border="1">
<tr id="a_tr"><td>hello world</td><tr>//我想在下面两个tr之间显示jquery返回的值,所以就加了个div,可这样不行啊

<tr><td><input type="hidden" id="idhidden" value='1'><input type='button' onclick="addnewRows()"></td></tr>
</table>
<script type="text/javascript">
<!--
function addnewRows() {
$("#a_tr").after("<tr><td>fuck the world</td></tr>");
}
//-->
</script>

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧