简体   繁体   中英

replace the value of data-href with the current url of the page every time button is pressed

Please tell me how to change the value of data-href when the button is pressed using php

<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>

Share on 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>

As Mike X and Naltroc said you can do it using jQuery, here is an example code:

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

finaly i got my answer window.location.href with some jquery did that job perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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