jQuery 工具是/否对话框:如何每页有多个?

发布于 2024-10-06 12:38:44 字数 746 浏览 6 评论 0原文

我有一个页面,上面有许多对象,其中一些对象可以根据用户请求删除。我想使用 jQuery 工具是/否覆盖来呈现“您确定吗?”在删除之前向用户输入对话框以获取确认。我已经改编了 jQuery 工具演示,并使其正常工作,位于至少到了没有的程度...

我已经按照 Flowplayer 演示获取了为每个“删除这个东西”链接创建的覆盖层,并且单击它们可以正确地显示覆盖层。我现在需要的是处理单击的代码来检查单击的按钮,如果单击“是”按钮,则从链接获取 href 并将页面重定向到该位置。在我看来,问题在于附加到包含 yes 和 no 按钮的 DIV 的单击处理程序没有任何方法来判断单击了哪个链接以导致其调用,因此它无法获得适当的href。 flowplayer 演示中的点击处理程序假定页面上只有一个位置可以调用叠加层。这对我不起作用——我有很多。

那么:有什么办法让它发挥作用吗?一定有什么事情,但我的大脑此时已经精疲力尽了。感谢您的帮助。


包含链接的链接如下:

  • delete此项目
  • 分配给叠加层的点击处理程序与 Flowplayer 演示中的内容基本没有变化。

    I've got a page with a number of objects on it, several of which can be deleted upon user request. I'd like to use the jQuery Tools yes/no overlay to present an "Are you sure?" type dialog to the user to get confirmation before doing the deletion. I've adapted the jQuery Tools demo, and have it working, at least up to the point where it doesn't....

    I've followed the flowplayer demo to get overlays created for each "delete this thing" link, and clicking on them is properly bringing up the overlay. What I now need is for the code handling the click to check the button that was clicked and, if the 'yes' button was clicked, get the href from the link and redirect the page to that location. The problem, as I see it, is that the click handler, which is attached to the DIV containing the yes and no buttons, doesn't have any way to tell which of the links was clicked on to cause its invocation, and so it can't get the appropriate href. The click handler in the flowplayer demo assumes that there is only a single place on the page where the overlay can get invoked. That doesn't work for me -- I have many.

    So: is there any way to get this to work? There's gotta be something, but my brain is exhausted at this point. Thanks for the help.


    the link containing the link is like this:

    <li class='yuimenuitem'><a class='yuimenuitemlabel modalInput' rel='#yesno' href='/slate/delete/12345'>delete this item</a></li>

    The click handler assigned to the overlay is essentially unchanged from what's in the flowplayer demo.

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

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

    发布评论

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

    评论(1

    宁愿没拥抱 2024-10-13 12:38:45

    您可以使用叠加层的 onBeforeLoad 事件来设置一个带有所单击按钮的 id 的变量。

    然后,当他们单击“是”或“否”时,按钮可以检查该变量并为用户加载正确的 URL。这是未经测试的,但类似的东西应该有效......

    var clicked;
    var links = [];//put a hash of button id's and links in here
    var triggers = $(".modalInput").overlay({
        mask: {
            color: '#ebecff',
            loadSpeed: 200,
            opacity: 0.9
        },
    
        onBeforeClick: function(event) {
            var element = e.originalTarget || e.srcElement;
            clicked = element.id
        },
    
        closeOnClick: false
    });
    var buttons = $("#yesno button").click(function(e) {
        var yes = buttons.index(this) === 0;
        if(yes) {
            window.location = links[clicked];
        }
    });
    

    You could use the onBeforeLoad event of the overlay to set a variable with the id of the button that was clicked.

    Then, when they click yes or no, the button can check that variable and load the correct URL for the user. This is untested, but something like this should work...

    var clicked;
    var links = [];//put a hash of button id's and links in here
    var triggers = $(".modalInput").overlay({
        mask: {
            color: '#ebecff',
            loadSpeed: 200,
            opacity: 0.9
        },
    
        onBeforeClick: function(event) {
            var element = e.originalTarget || e.srcElement;
            clicked = element.id
        },
    
        closeOnClick: false
    });
    var buttons = $("#yesno button").click(function(e) {
        var yes = buttons.index(this) === 0;
        if(yes) {
            window.location = links[clicked];
        }
    });
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文