简体   繁体   English

如何隐藏锚标记并在同一位置显示另一个锚标记

[英]How to hide an anchor tag and display another anchor tag in the same place

I have the following anchor attributes defined in my JSP. 我在JSP中定义了以下锚属性。 Once I click the 'Add All Plans To Cart', I want the 'Add All Plans to Cart' button to hide and 'Remove All Plans From Cart' to be displayed in the same place as 'Add All Plans to Cart'. 单击“将所有计划添加到购物车”后,我希望隐藏“将所有计划添加到购物车”按钮,并将“从购物车中删除所有计划”显示在与“将所有计划添加到购物车”相同的位置。

Hide and Show is working fine. 隐藏和显示工作正常。 But the 'Remove All Plans From Cart' is displayed on the next line . 但是,“从购物车中删除所有计划”显示在下一行。 I want it to exactly replace the 'Add All Plans To Cart' button. 我希望它完全替换“将所有计划添加到购物车”按钮。 I tried various approaches including document.getElementById and inline,inline-block ete in my Javascript file but none of them worked. 我尝试了多种方法,包括我的Javascript文件中的document.getElementById和inline,inline-block ete,但这些方法均无效。

Appreciate any inputs.Thanks. 感谢任何输入。谢谢。

JSP JSP

<a id="selectAll" class="primaryButton btn btn-small" style="margin-left:10px">
    Add All Plans To Cart
</a>

<a id="removeAll" style="display:none" class="primaryButton btn btn-small" style="margin-left:10px">
    Remove All Plans From Cart
</a>    

Javascript 使用Javascript

$("#selectAll").click(function () 
{
    $("#selectAll").hide();
    $("#removeAll").show();
});

Bootstrap buttons should preferably be used in their own element, try to wrap them inside another element which is then hidden by your code. 自举按钮最好应在其自己的元素中使用,尝试将它们包装在另一个元素中,然后将其隐藏在您的代码中。

<span id="selectAll" style="margin-left:10px">
  <a class="primaryButton btn btn-small">
    Add All Plans To Cart
  </a>
</span>

<span id="removeAll" style="margin-left:10px; display:none">
  <a class="primaryButton btn btn-small">
    Remove All Plans From Cart
  </a>   
</span>

There's little wrong in your jQuery. 您的jQuery几乎没有错。 You are missing the ending round bracket ) and semicolon ; 您缺少结尾的圆括号和分号; . So your jQuery should look something like this : 因此,您的jQuery应该看起来像这样:

jQuery : jQuery的:

$("#selectAll").click(function () {
     $("#selectAll").hide();
     $("#removeAll").show();
});

Now as i've tried in the following fiddle here , the anchors are displayed in same position. 现在,我在下面的小提琴已经试过这里 ,锚被显示在相同的位置。 So there might be something wrong with your css code. 因此,您的CSS代码可能有问题。

Share the css code to get in detailed solution. 共享CSS代码以获取详细的解决方案。

how about float both button, if this won't help, you should public your all code somewhere, jsfiddle for example 如何同时浮动两个按钮,如果这样做无济于事,则应将所有代码公开在某个地方,例如jsfiddle

#selectAll, #removeAll {
    float: left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM