【问题标题】:How to pass value to jquery dialog?如何将值传递给 jquery 对话框?
【发布时间】:2015-09-15 17:08:29
【问题描述】:

如何在按钮单击时将buttonid 值传递给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 吗?如果是这样,那么没有,除了通过查询字符串之外别无他法。如果您只需要浏览器中的值,您可以将其存储在全局变量中,甚至存储在localStoragesessionStorage 中。

标签: c# jquery asp.net asp.net-mvc jquery-dialog


【解决方案1】:

你可以改变这一行

var Id=$(this).atrr('id'); To BTW atrr is suppose to be attr 
CurrentId = $(this).attr('id'); without the var

然后在 /Dictionary/_Create 页面中,您可以使用 javascript 简单地访问 CurrentId 变量,因为它是全局变量

【讨论】:

  • 试用后会回来的。
猜你喜欢
  • 2013-02-25
  • 1970-01-01
  • 1970-01-01
  • 2021-09-28
  • 1970-01-01
  • 1970-01-01
  • 2010-09-28
  • 1970-01-01
  • 2013-07-06
相关资源
最近更新 更多