每次按下按钮,都会将data-href的值替换为页面的当前网址

时间:2017-10-17 04:43:31

标签: javascript php jquery

请告诉我如何使用php

按下按钮时更改data-href的值
<div class="fb-send" data-href="http://wishindia.in/wishindia/Diwali/index.php?name=Ram&amp;message=Jai+Shri+Ram"></div>
<div class="fb-share-button" data-href="http://wishindia.in/wishindia/Diwali/index.php?name=Mk&amp;message=Share+button" data-layout="button_count" data-size="small" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwishindia.in%2Fwishindia%2FDiwali%2Findex.php%3Fname%3DMk%26message%3DShare%2Bbutton&amp;src=sdkpreparse">Share</a></div>

分享Whatsaps

<div id="mobile-share">
  <a href="whatsapp://send?text=http://wishindia.in/wishindia/Diwali/index.php?name=asdfa&message=asdfadf" data-action="share/whatsapp/share">Share on Whatsaps</a>
</div>


buttton
<a href="#" class="newwish" data-toggle="modal" data-target="#myModal">Send</a>

2 个答案:

答案 0 :(得分:0)

正如Mike X和Naltroc所说,你可以使用jQuery来做,这是一个示例代码:

$(".fb-send").click(function(event){
    event.preventDefault();// this will stop redirecting to other page
    $(this).attr("href", "https://www.google.com");
});

答案 1 :(得分:0)

 <p><a href="https://www.w3schools.com" id="w3s">W3Schools.com</a></p>
 <button>Change href Value</button>

 <script>
 $(document).ready(function(){
     $("button").click(function(){
        $("#w3s").attr("href", window.location.href);
     });
 });
 </script>

最后我得到了我的答案window.location.href,其中一些jquery完成了这项工作。