<a class="format">123</a><br />
<a class="format">456</a>
<script type="text/javascript">
$(".format").click(function(iFormat) {
$.ajax({
type: "post",
url: "test.aspx/chooseFormat",
data:{"str":iFormat},
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(‘’);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
</script>
[WebMethod]
public static void chooseFormat(string str)
{
string aaa = str;
}
问题描述:
1.我界面有好多的<a>,我想通过点击实现调用同页面后aspx.cs里的chooseFormat方法并传递参数 str
2.每个<a>在触发ajax时需要给iFormat不同的值,在<a class="format">123</a> 传递123 123的位置可以发生变化,比如:id="123"或其他
求解。求解.....
------最佳解决方案--------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm15.aspx.cs" Inherits="Linq_Test.WebForm15" %>
<!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 runat="server">
<title></title>
<script src="jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".format").each(function () {
$(this).bind("click", function () {