如何将数值从链接传递到同一页面上的脚本

时间:2015-11-13 21:34:34

标签: javascript jquery facebook

我正在使用Facebook图库插件在我的图库页面上显示我的相册,但我想通过链接控制相册来选择。

onlyAlbum:875640352512391,这是要加载的相册的编号,所以我必须将一些数字从我的菜单传递到此设置。 我希望有人可以提供帮助。



MENU:
      <div style="float: left; width: 200px;">
      	<h1 class="memberstitle"><span>The Gallery</span></h1>
        <ul id="nav">
          <li><a href="#" id="here">Gallery</a>
            <ul>
              <li><a href="#" target="gallery">photos</a></li>
              <li><a href="#" target="gallery">photos</a></li>
              <li><a href="#" target="gallery">photos</a></li>
              <li><a href="#" target="gallery">photos</a></li>
            </ul>
          </li>
          <li><a href="index.html">Back to home</a></li>
        </ul>
      </div>

JavaScript:
<div class="fb-album-container"></div>

<script type="text/javascript">
    $(document).ready(function () {
      $(".fb-album-container").FacebookAlbumBrowser({
            account: "natgeo",
            accessToken: "***************|***************",
            onlyAlbum: "10150310813623951",
            showComments: true,
            commentsLimit:3,
            showAccountInfo: true,
            showImageCount: true,
            showImageText: true,
            shareButton: false,
            albumsPageSize: 0,
            photosPageSize: 0,
            lightbox: true,
            photosCheckbox: true,
			pluginImagesPath: "../src/",
            likeButton: true,
            shareButton: true,
            addThis:"ra-52638e915dd79612",
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

我会尝试解决此问题,因为您的代码段不完整,但您可以执行以下操作:

&#13;
&#13;
$(document).ready(function() {
  loadGallery('10150310813623951');
  $('a[target=gallery]').click(function(){
    var id=$(this).data('gallery-id');
    loadGallery(id);
    return false;
  });
});

function loadGallery(id) {
  alert('Loading gallery #'+id);
/*  $(".fb-album-container").FacebookAlbumBrowser({
    account: "natgeo",
    accessToken: "775908159169504|cYEIsh0rs25OQQC8Ex2hXyCOut4",
    onlyAlbum: id,
    showComments: true,
    commentsLimit: 3,
    showAccountInfo: true,
    showImageCount: true,
    showImageText: true,
    shareButton: false,
    albumsPageSize: 0,
    photosPageSize: 0,
    lightbox: true,
    photosCheckbox: true,
    pluginImagesPath: "../src/",
    likeButton: true,
    shareButton: true,
    addThis: "ra-52638e915dd79612",
  });*/
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="float: left; width: 200px;">
  <h1 class="memberstitle"><span>The Gallery</span></h1>
  <ul id="nav">
    <li><a href="#" id="here">Gallery</a>
      <ul>
        <li><a href="#" target="gallery" data-gallery-id='12345'>photos</a>
        </li>
        <li><a href="#" target="gallery" data-gallery-id='44444'>photos</a>
        </li>
        <li><a href="#" target="gallery" data-gallery-id='66666'>photos</a>
        </li>
        <li><a href="#" target="gallery" data-gallery-id='88888'>photos</a>
        </li>
      </ul>
    </li>
    <li><a href="index.html">Back to home</a>
    </li>
  </ul>
</div>


<div class="fb-album-container"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你想要解析一个字符串并把它放在你的HTML中吗?或者您是否想要扫描HTML并使用其中的内容来填充您的js?

如果要解析HTML,则应查看jquery.parseHTML()。或者,如果要将其从JS插入HTML,请查看DOM Insert