简体   繁体   English

首次单击html.disable link.in html.java后隐藏链接

[英]hiding a link after first click in html.disable link.in html.java

I am passing some values through a link "Like",I want to set the property such that the link is hidden or disabled if it is clicked once.. have tried this code 我通过链接“赞”传递一些值,我想设置属性,以便链接被隐藏或禁用,如果它被点击一次..尝试此代码
onclick="this.style.display='none';"

But it does not seems to be working.Please help as where to put the js or any other alternate method.. 但它似乎没有工作。请帮助在哪里放置js或任何其他替代方法..

<a href="like1?sellerid=<s:property value="id"/>&property_id=<s:property value="p_id"/>"onclick="hide">Like</a>;'  

As it has been said this functions is better to be implemented with javascript. 据说这个函数最好用javascript实现。 First assign a valid id for the link and follow this: 首先为链接分配一个有效的ID,然后按照:

//create a function for the click like:
$('#buttonId').click(hideButton);

Afterwards, in your javascript code: 之后,在您的javascript代码中:

function hideButton(){$('#buttonId').css({'visibility':'hidden'})};

Remember to import jquery library and import the .js when your code has been displayed if you does not use a .ready function. 如果不使用.ready函数,请记住导入jquery库并在显示代码时导入.js。

Edit: note that in the way previously exposed you will still get the box where the link was, but it is displayed hidden. 编辑:请注意,在以前曝光的方式中,您仍然会获得链接所在的框,但它显示为隐藏。

If you need to pass some values as well as hide element i thing you should use ajax. 如果你需要传递一些值以及隐藏元素我应该使用ajax。 As you are passing a url to href attribute it will redirect you to that page. 当您将url传递给href属性时,它会将您重定向到该页面。 A java script function can work better. java脚本函数可以更好地工作。 Call a javascript function on onClick event like 在onClick事件上调用javascript函数

<a href="#""onclick="hide()">Like</a>

<script>
function hide(){
// ajax call to send parameter
// hide element
}

</script>

Define a class for anchor tag , and user ajax post to send the request and then you can just hide the element with hide() . anchor标记定义一个类,并使用用户ajax发送请求,然后你可以用hide()隐藏元素。

See below example: 见下面的例子:

 $(".like").on("click", function (e) { e.preventDefault(); $.post(this.href); $(this).hide(); }); 
 <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="like" href="like1?sellerid=-1">Hide me</a> 

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

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