将程序生成的值从列表项传递给jquery函数
本文关键字:jquery 函数 列表 程序生成 | 更新日期: 2023-09-27 18:27:47
我有一个数据表生成的列表,其中包含一组特定的属性。我想将某个属性传递给jquery函数,然后jquery函数将该属性添加到POST,然后将用户重定向到另一个页面。我不确定这是否是最好的方法,但我很难实现。
现在我只是想测试如何将值实际传递给jquery函数。这是生成列表项的codeehind:
protected void BuildReportList(DataTable dt)
{
string groupHeader = "";
foreach (DataRow row in dt.Rows)
{
ListItem myItem = new ListItem();
myItem.Text = row["prg_menu"].ToString();
myItem.Attributes.Add("title", row["prg_description"].ToString());
myItem.Attributes.Add("onClick", "test();");
myItem.Attributes.Add("value", row["prg_path"].ToString().Trim());
reportsList.Items.Add(myItem);
}
}
这是jquery函数,现在我正试图用传递的值弹出一个警报:
function test() {
alert(($this).attr("value"));
}
关于我在这里做错了什么,有什么建议吗?
试试这个方法:
myItem.Attributes.Add("onClick", "test(this);");
和:
function test(item) {
alert($(item).val());
}
有更多选项可以检查元素的值:
$(item).attr("value");
或不带jQuery包装:
item.value;