使用“对话框”仅帮助打开一个元素MVC 环境下 JQuery (UI) 中的函数

发布于 2024-10-05 18:34:23 字数 1362 浏览 2 评论 0原文

大家好,如果我遗漏了任何细节,请提前原谅我,因为这是我在这里的第一篇文章:

我在使用对话框 JQuery 命令时遇到问题。更具体地说,我希望名为“编辑”的按钮(下面第 7 行)仅打开 1 个窗口,而不是所有窗口都在彼此后面。下面是我现在使用的一些代码以及该代码发生的情况的简短描述。预先感谢您的阅读!

<!-- C# and HTML code here-->
<table> 
<tbody>
        <% foreach (var item in Model) { %>
    <tr>
    <td>    
                <button class="opener">Edit</button>
                <div class="dialogButton" title="Something"><% Html.RenderAction("Something", "Admin", new { id = item.ID }); %></div>
                 <td>Other values</td>
                  </tr>
</table>

<!-- JQ script is here-->
$(".dialogButton").dialog({ autoOpen: false });
            $(".dialogButton").dialog({ buttons: { "Ok": function () { $(this).dialog("close"); } } });
            $(".dialogButton").dialog({ show: 'fade' });
            $('.opener').click(function () { $('.dialogButton').dialog('open'); });

到目前为止,应用程序所做的是加载表格,并在每行旁边有一个编辑按钮(上面第 7 行),但是当按下“编辑”按钮时,Html.RenderAction(第 8 行)会拉出所有行的编辑窗口。列表中的项目 (item.ID),而不仅仅是选定的一行。这意味着目前大约有 25 个窗口在彼此后面弹出。

我希望代码执行的操作但到目前为止无法弄清楚只是打开所选行的编辑窗口。

还建议将上面代码中的最后一行(最后一行 17 行)替换为以下代码:

$('.opener').click(function () { $(this).next().dialog('open'); });

理论上,这应该只打开一个元素,但事实并非如此。请帮忙!

再次感谢您!

Hello everyone and please forgive me in advance if I leave any details out as this is my first post here:

I have a problem using dialog JQuery command. More specifically, I want the button called "Edit" (line 7 below) to open only 1 window as opposed to all behind each other. Below is some of the code I use right now and a short description of what happens with the codde. Thank you in advance for reading!

<!-- C# and HTML code here-->
<table> 
<tbody>
        <% foreach (var item in Model) { %>
    <tr>
    <td>    
                <button class="opener">Edit</button>
                <div class="dialogButton" title="Something"><% Html.RenderAction("Something", "Admin", new { id = item.ID }); %></div>
                 <td>Other values</td>
                  </tr>
</table>

<!-- JQ script is here-->
$(".dialogButton").dialog({ autoOpen: false });
            $(".dialogButton").dialog({ buttons: { "Ok": function () { $(this).dialog("close"); } } });
            $(".dialogButton").dialog({ show: 'fade' });
            $('.opener').click(function () { $('.dialogButton').dialog('open'); });

What the application does so far is it loads the table and has an edit button next to each row (line 7 above), however when the "Edit" button is pressed the Html.RenderAction (line 8) pulls up edit windows for all of the items (item.ID) on the list instead of only the selected one row. This means that there are currently about 25 windows that pop up behind each other.

What I want the code to do but so far was unable to figure out is only to open the edit window for selected row.

It has also been suggested to replace the last line in the code above (line 17, last) with the following code:

$('.opener').click(function () { $(this).next().dialog('open'); });

In theory this is suppose to open only one element but it does not. Please help!

Thank you again!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放赐 2024-10-12 18:34:23

只需为每个 div class="dialogBu​​tton" 和按钮 class="opener" 添加唯一 ID,

例如 div class="dialogBu​​tton" id="DialogBu​​tton_1" 和
Button class="opener" id="opener_1。使用 item.ID 或其他唯一的东西。

然后使用 ID

$('.opener').click(function () { $('#dialogBu​​tton_ '+$(this).attr('id')).dialog('open'); });

基本上,您将通过这种方式调用对应于 opener 的对话框

希望这对您来说听起来合乎逻辑。

Just put unique ID for each div class="dialogButton" and button class="opener"

like div class="dialogButton" id="DialogButton_1" and
button class="opener" id="opener_1. Use item.ID or something else that is unique.

and then call the dialog plugin with the ID

$('.opener').click(function () { $('#dialogButton_'+$(this).attr('id')).dialog('open'); });

Basically you will be calling the dialog that coresponds to the opener this way

Hope that sound logical for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文