2011-12-19 64 views
0

我試圖做一個動態的類似fb的按鈕來獲取頁面位置,但我正在尋找替代html的data-href元素的最佳實踐:渲染類似按鈕的facebook與top.location.href

我有拼圖兩個部分組成:

  1. <div class="fb-like" data-href='' data-send="true" data-colorscheme="dark" data-width="450" data-show-faces="true"></div>
  2. top.location.href

哪個JS方法將允許top.location.href到replac e數據 - href元素,並呈現Facebook像按鈕?

回答

1

像你一樣會?

document.getElementById("the_like_button").setAttribute("data-href", new_value); 

或:

$("#the_like_button").attr("data-href", new_value); 

如果你喜歡的jQuery。