0

我有一个问题,我很困惑为什么我的代码不起作用,我试图在单击列表项锚标记时将 PHP 文件加载到 div 中。

代码:

<script type="text/javascript">
$(document).ready(function() {


//I have these 2 functions aswell that DO work

 $(".itm1 a").click(function(evt) {
     var page = $(this).attr('href');
     $("#page1").load(page);
     evt.preventDefault();
  });

  $(".footnav a").click(function(evt) {
     var page3 = $(this).attr('href');
     $("#page1").load(page3);
     evt.preventDefault();
  });
// ---------------------------

  $(".needslist a").click(function(evt) {
     var page4 = $(this).attr('rel');
     $("#page1").load(page4)
     evt.preventDefault();
  });



});
</script>


<ul>
 <li class="needslist"><span><a rel="/ceos.php" href="#">Are you a CEO SPEECH-MAKER or ENTREPRENEURIAL VISIONARY?</a></span><br />
            who wants the best advice and counsel from an expert coach for your own speeches and leadership events that include speaking to investors, stakeholders, business collaborators, board of directors, conferences and/or the media?</li><br />

 </ul>

谁能解释为什么它不起作用?

编辑:好的,伙计们,所以我发现一旦我通过 ajax 加载了一个 div,该内容就无法处理 jquery。这是我的问题....如何在加载的内容上执行 jquery 脚本??????!!!

4

1 回答 1

1

找到了解决方案:

加载 ajax 内容后,您无法对该加载的内容执行任何脚本,这是我的解决方案:

$(".needslist a").live("click", function(evt) {
     var page4 = $(this).attr('rel');
     $("#page1").load(page4);
     evt.preventDefault();
  });
于 2012-08-15T19:58:39.987 回答