JQuery UI Accordion,如何使用另一个功能将按钮/链接放置到标题

发布于 2025-01-03 03:46:17 字数 425 浏览 0 评论 0原文

我真的对这个问题很生气,我很高兴能从你那里得到一点帮助。

我确实有一个工作正常的 JQuery 手风琴。我喜欢在标题的右角放一个 X,然后从列表中删除该项目,但我无法这样做。 标头本身位于

内。 HEADER 标签。这是打开内容。 当我将另一个链接放置到标题时,手风琴未正确显示。 是否有机会放置另一个链接/按钮,如果用户单击它,我可以捕获它并删除该项目?

我尝试了另一种方法,我将按钮放在内容中的 div 中,并尝试通过位置将其移动到顶部:relative 和 -20px,但它没有显示,它被从标题覆盖,尽管我将 Z-INDEX 设置为更高的价值。

听起来像是一件非常简单的事情,也许我错过了一些东西......但我现在花了很多时间在这上面并搜索了很多网站但无法解决它。 任何帮助将不胜感激。

谢谢, 马塞尔

I'm really getting mad about this issue and I would be glad to get a little bit help from you.

I do have a JQuery accordion which is working fine. I like to put a X in the right corner of the header which then deletes the item from the list but I'm not able to do that.
The header itself is within a <h3><a> HEADER </a></h3 tag. this is opening the conent.
When I put another link to the header the accordion is not shown correctly.
Is there a chance to put on another link/button, and if the user clicks on it I can catch it and delete the item?

I tried another method, I put the button in a div in the content and tried to move it to the top via position: relative and -20px, but it's not shown, it's overwritten from the header, although I set the Z-INDEX to a higher value.

Sounds like a very easy thing, and maybe I missed something... but I spent so many hours on this now and searched so many sites but was not able to solve it.
Any help would be appreciated.

Thanks,
Marcel

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

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

发布评论

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

评论(4

养猫人 2025-01-10 03:46:17

这有助于我将 UI 按钮放入 UI 手风琴标头中,而不会干扰事件:

$( "#accordion" ).accordion({ header: "> div > .h3" });
$( "#check" ).button();
$( "#check-label" ).click(function(event){
    event.stopPropagation(); // this is
    event.preventDefault(); // the magic
    log("clicked!");
});

<div id="accordion">
    <div>
        <div class="h3">
            <div class="right-button">
                <input type="checkbox" id="check" /><label for="check" id="check-label"></label>
            </div>
            <a href="#">First</a>
        </div>
        <div>
            <p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</p>

        </div>
    </div>
    <div>
        <div class="h3">
            <a href="#">Second</a>
        </div>
        <div>Phasellus mattis tincidunt nibh.</div>
    </div>
    <div>
        <div class="h3">
            <a href="#">Third</a>
        </div>
        <div>Nam dui erat, auctor a, dignissim quis.</div>
    </div>
</div>

This helps me to put UI-button into UI-accordion header without interfere of events:

$( "#accordion" ).accordion({ header: "> div > .h3" });
$( "#check" ).button();
$( "#check-label" ).click(function(event){
    event.stopPropagation(); // this is
    event.preventDefault(); // the magic
    log("clicked!");
});

<div id="accordion">
    <div>
        <div class="h3">
            <div class="right-button">
                <input type="checkbox" id="check" /><label for="check" id="check-label"></label>
            </div>
            <a href="#">First</a>
        </div>
        <div>
            <p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</p>

        </div>
    </div>
    <div>
        <div class="h3">
            <a href="#">Second</a>
        </div>
        <div>Phasellus mattis tincidunt nibh.</div>
    </div>
    <div>
        <div class="h3">
            <a href="#">Third</a>
        </div>
        <div>Nam dui erat, auctor a, dignissim quis.</div>
    </div>
</div>
宫墨修音 2025-01-10 03:46:17

这是一篇较旧的文章,但对于那些正在寻找的人来说,这就是我最终所做的就是在 h3 标头内创建一个块。然后我将名为工具栏的类添加到块中。然后使用 jquery 选择器获取带有工具栏类的块内的所有锚点,并绑定每个锚点的单击事件。在单击事件中,我使用当前元素的 href 属性来设置 window.location 值,以强制浏览器到达我想要导航到的页面。在本例中,它是一个编辑和删除页面。

<div id="accordion">
   <h3>Header 1
   <span style="float:right;" class="toolbar ui-widget-header ui-corner-all">
     <a href="/EditPage.html">Edit</a>
     <a href="/DeletePage.html">Delete</a>
   </span>
   </h3>
   <div>
    Content 1
   </div>
   <h3>Header 2
   <span style="float:right;" class="toolbar ui-widget-header ui-corner-all">
     <a href="/EditPage.html">Edit</a>
     <a href="/DeletePage.html">Delete</a>
   </span>
   </h3>
   <div>
    Content 2
   </div>
</div>

<script type="text/javascript">
 $("#accordion").accordion();

 $(".toolbar a").live("click", function() { 
  window.location($(this).attr("href")); 
 }); 
</script>

An older post, but for those looking, this is what I ended up doing is creating a block inside of the h3 header. Then I added the class called toolbar to the block. Then used the jquery selector to get all the anchors inside of the blocks with the toolbar class and bind the click event of each. Inside the click event, I used the current elements href attribute to set the window.location value to force the browser to the page I wanted to navigate to. In this instance it is an edit and delete page.

<div id="accordion">
   <h3>Header 1
   <span style="float:right;" class="toolbar ui-widget-header ui-corner-all">
     <a href="/EditPage.html">Edit</a>
     <a href="/DeletePage.html">Delete</a>
   </span>
   </h3>
   <div>
    Content 1
   </div>
   <h3>Header 2
   <span style="float:right;" class="toolbar ui-widget-header ui-corner-all">
     <a href="/EditPage.html">Edit</a>
     <a href="/DeletePage.html">Delete</a>
   </span>
   </h3>
   <div>
    Content 2
   </div>
</div>

<script type="text/javascript">
 $("#accordion").accordion();

 $(".toolbar a").live("click", function() { 
  window.location($(this).attr("href")); 
 }); 
</script>
酷炫老祖宗 2025-01-10 03:46:17

只需捕获手风琴激活并在单击不应触发手风琴的元素时阻止它

$("#accordion").accordion({
     beforeActivate: function(event, ui) {
          var target = event.originalEvent.target;
          if (target.text == "x") {
             //do your logic
             return false;
         }
     }
});

Just catch accordion activation and prevent it if click occurs on element which should not trigger accordion

$("#accordion").accordion({
     beforeActivate: function(event, ui) {
          var target = event.originalEvent.target;
          if (target.text == "x") {
             //do your logic
             return false;
         }
     }
});
烟酉 2025-01-10 03:46:17

其他答案可能在某些时候有效,并且可能在某些情况下有效。

相反,我发现将这两种方法与现代 jQuery 和 Javascript 结合使用是可行的。我将一组链接放入职位发布列表中,这些链接都在“applyNowLink”类中:

$( ".applyNowLink" ).on("click", null, null, function(event) { 
      window.location.href = $(this).attr("href"); 
      event.preventDefault(); 
 }); 

对我有用。不阻止默认操作导致打开两个电子邮件窗口(href 是 mailto:

It's possible that the other answers worked at some time, and may have worked in certain circumstances.

I've found instead that it works to use a combination of the two approaches, with modern jQuery and Javascript. Where I've put in a set of links into a list of job postings, and the links are all in the 'applyNowLink' class:

$( ".applyNowLink" ).on("click", null, null, function(event) { 
      window.location.href = $(this).attr("href"); 
      event.preventDefault(); 
 }); 

Works for me. Not preventing the default action caused two email windows to open (the href is a mailto:)

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