javascript - 将按钮值传递给模态中的 Url.Action

标签 javascript jquery json button

我怎样才能在按钮上传递这个值(按钮启动js onclick):

<button class="launch" value= @item.Id  role="button" name="dId">do it</button>

$(this).load("@Url.Action("myPartial", new { id = 1 })");

我希望将 1 替换为按钮中的 @item.Id 值。谢谢。

这是脚本:

<script>
    $(function () {
        $("modal").dialog({
            autoOpen: false,
            height: 600,
            width: 700,
            modal: true,
            open: function (event, ui) {
                $(this).load("@Url.Action("myPartial", new { id = 1 })");
            },
                buttons:{
                    "Close": function () {
                        $(this).dialog("close");
                    }
                }
        });
        $(".launch").click(function () {
            $("#modal").dialog("open");
        })
    });
</script>

最佳答案

向按钮添加 ID:

HTML:

<button class="launch" value= "@item.Id" id="button" role="button" name="dId">do it</button>

JS:

var button=document.getElementById("button");
$(this).load("@Url.Action("myPartial", new { id ="button.value" })");

这是您要找的吗?

关于javascript - 将按钮值传递给模态中的 Url.Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23466165/

相关文章:

javascript - 在元素中组织 CSS/JavaScript 的最佳方式是什么

javascript - Jquery 数据表复选框过滤器

c# - ssis - 美化json字符串

json - 序列化不带引号的 C# 对象

javascript - 计数器不会在页面加载时开始计数

javascript - 将一种数据结构转换为另一种数据结构 JavaScript/TypeScript

jquery - 更改 Kendo UI 网格层次结构的宽度?

android - 使用 Retrofit 解析动态 key Json 字符串

javascript - 将一个 html (bootstrap) 表的数据附加到另一个 bootstrap 表

javascript - 从 DIV 创建数组,然后检查相似性