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 :
<?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.
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. Can someone show me the correct way开发者_如何学运维?
Thank you
-mike
Make sure that you generate a complete href attribute:
<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):
$(function() {
$('a').click(function() {
$('#div').load(this.href);
return false;
});
});
精彩评论