【发布时间】:2015-09-15 17:08:29
【问题描述】:
如何在按钮单击时将button 的id 值传递给jquery dialog。
我不想使用query string 传递值。有什么方法可以直接使用jquery dialog 的属性或属性传递值。
查看:
<input type="button" value="Create New" class="Create" id="1"/>
jquery:
$(".Create").on("click", function (e) {
var Id=$(this).atrr('id');
$('#Load').empty();
//overflow: visible !important;
e.preventDefault();
$('#Load').dialog({
autoOpen: true,
modal: true,
draggable: true,
resizable: false,
height: 500,
width: 600,
position: { my: "center", at: "center", of: window },
dialogClass: 'fixed-dialog',
title: 'Create New Word',
open: function (event, ui) {
$(this).load("/Dictionary/_Create");
},
//close: function (event, ui) {
// window.location.href = window.location.href;
//}
});
return false;
});
【问题讨论】:
-
如果您已经拥有
id值,您是否尝试在open处理程序中使用它?作为旁注,您应该使用var id = this.id;来获取id;当您可以使用 Vanilla JS 时,无需将 DOM 元素转换为 jQuery 对象然后获取属性... -
任何代码 plz ,您建议如何通过 open handler 使用?
-
open: function (event, ui) { alert(Id); $(this).load("/Dictionary/_Create");} -
我可以得到 id 值,正如你所建议的,但是我如何将这个值传递给 _Create 部分视图,我不想使用查询字符串发送这个值,即 _Create?id=Id ,由于我不想弄乱控制器中的代码,有什么解决方案可以直接将值传递给_Create而不在查询字符串中传递值?
-
你的问题不是很清楚。如果我理解正确,您想将
id发送到服务器。如果是这样,那么它真的取决于你想要完成什么。您在服务器上需要这个id吗?如果是这样,那么没有,除了通过查询字符串之外别无他法。如果您只需要浏览器中的值,您可以将其存储在全局变量中,甚至存储在localStorage或sessionStorage中。
标签: c# jquery asp.net asp.net-mvc jquery-dialog