0

I would really appreicate any help on this matter. Here is the code that I have so far:

    $('.Ajax_links').click(function() {
  window.location.hash = $(this).attr("href");
  var href = $(this).attr('href');  
  $('#contaniner_div').load(href);

  $('data-target').click(function() {
  var data-target = $(this).attr('data-target');
  $('#contaniner_Div_Nav').load(this.data-target);
  }

 return false;
});

I would like that messed up code above to load contents into these two divs below when the link with the class set to (class="Ajax_links") is clicked:

<div id="contaniner_Div"></div>
<div id="contaniner_Div_Nav"></div>

This is how the link looks:

<a href="files/content.html" class="Ajax_links" data-target="files/navigation.html">

The first method that I was working with with the rel instead of the data-target method loaded content into these two divs when the link is clicked but the rel part of that content was not included into the hash. Making it impossible for me to bookmark the rel part of link or if I wanted to go back/forward by using the browsers buttons. (I'm using the ben Alman plugin). So now I am searching for a different method, but my code doesn't work. Could someone please help me?

4

2 回答 2

1

正如 David Thomas 指出的那样,您似乎也承认,$(this)您的代码中的 jQuery 包装器是围绕文档对象的。该对象没有rel属性,$(this).attr("rel")value 也是如此undefined。在 JavaScript 中,undefined != "", 表达式的计算结果为 true,然后您将其设置window.location.hash另一个未定义的值:$(this).attr("href"). 这就是为什么您会看到类似domain/#undefined.

我还应该指出,您滥用relHTML 锚标记上的属性。

该属性描述了从当前文档到由 href 属性指定的锚点的关系。此属性的值是以空格分隔的链接类型列表。

这是有效链接类型的列表data-使用属性存储有关 HTML 元素的任意元数据会更好。

于 2012-07-08T03:32:36.837 回答
1

我认为您将需要一个用于后退按钮和历史记录支持的插件。这一个通常被认为是相当不错的:

http://benalman.com/projects/jquery-bbq-plugin/

于 2012-07-07T17:38:39.837 回答