62,046
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
$(function () {
$("#Edit").click(function () {
//这里应该怎么传递参数到后台?
})
})
$(function () {
$("#Edit").click(function () {
var url = "后台页处理面地址";
var params = { "Command": "Edit", "Id": 1 }; //构造一个参数
$.post(url, params, function (res) {
var result = $.parseJSON(res);
alert(result.message);
});
})
})
protected void Page_Load(object sender, EventArgs e) {
string command = Request["Command"]; //接受前台提交的命令
if (command != null) {
Response.ContentType = "text/plain";
Response.ContentEncoding = Encoding.UTF8;
switch (command) {
case "Edit":
string id = Request["Id"];//获取id
//执行代码
Response.Write("{message:'操作成功!'}");//构造一个json,或者要简单直接写个字符串 '操作成功'输出也可以
break;
}
try {
Response.End();//输入结果,并终止
} catch {
//这里可能会引发一个线程终止的异常,不用管它
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script>
<!--
$().ready(function() {
$("[id*='edit_']").click(function() {
Modify($(this).attr("id").slice(5));
});
function Modify(id) {
alert(id);
}
});
-->
</script>
</head>
<body>
<table>
<tr><td>aaaaa</td><td><a href="javascript:void(0);" id="edit_1">编辑</a></td></tr>
<tr><td>bbbbb</td><td><a href="javascript:void(0);" id="edit_2">编辑</a></td></tr>
<tr><td>ccccc</td><td><a href="javascript:void(0);" id="edit_3">编辑</a></td></tr>
<tr><td>ddddd</td><td><a href="javascript:void(0);" id="edit_4">编辑</a></td></tr>
<tr><td>eeeee</td><td><a href="javascript:void(0);" id="edit_5">编辑</a></td></tr>
</table>
</body>
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script>
<!--
$().ready(function() {
$("#list tr").click(function() {
Modify($(this).attr("id"));
});
function Modify(id) {
alert(id);
}
});
-->
</script>
</head>
<body>
<table id="list">
<tr id="1"><td>aaaaa</td></tr>
<tr id="2"><td>bbbbb</td></tr>
<tr id="3"><td>ccccc</td></tr>
<tr id="4"><td>ddddd</td></tr>
<tr id="5"><td>eeeee</td></tr>
<table>
</body>
<html>