简体   繁体   English

jQuery获取href值并放入ajax.load

[英]jquery get href value and put into ajax.load

I have a page where ID is generated dynamically and be fetch from database and I put the result inside <a> tag : 我有一个页面,其中ID是动态生成的,可以从数据库中获取,并将结果放入<a>标记中:

<?php while($row = mysql_fetch_array($result))
  { ?>
 <a href="<?php echo $row['id']; ?>" onclick="myfunc(); return false;">ID Number 1</a><br />
 <a href="<?php echo $row['id']; ?>" onclick="myfunc(); return false;">ID Number 2</a>
<?php } ?>

and when user click the link, the javascript myfunc() function will be trigger. 当用户单击链接时,将触发javascript myfunc()函数。

function myFunc(){  
  $("#div").load("get_id.php?","id="+"SHOW THE $row['id'] HERE"); }             

But I don't know how to retrieve href value and put it inside the load() method. 但是我不知道如何检索href值并将其放在load()方法内。 Can someone show me the correct way? 有人可以告诉我正确的方法吗?

Thank you 谢谢

-mike -麦克风

Make sure that you generate a complete href attribute: 确保您生成完整的href属性:

<a href="get_id.php?id=<?php echo $row['id']; ?>">ID Number 1</a>

and then attach a click handler unobtrusively (don't mix markup and javascript): 然后毫不客气地附加点击处理程序(不要混用标记和javascript):

$(function() {
    $('a').click(function() {
        $('#div').load(this.href);
        return false;
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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