Retrieving data needed for ajax call for multiple lines
I have a table with many rows. When you click on these rows they open up more detail about the row you click in. This could be based on an int or string.开发者_开发技巧
I have wired jQuery up to anchor tags on each row which the user will click on. However previously when using Javascript inline you would pass something like this:
<a href="javascript: openNext('000001')"><img /></a>
Now when using events, I have lost the link to the '000001'. Where should this value be placed for reference?
How about something like this?
<div id="somecontainer">
<a href="#000001"><img /></a>
...
</div>
<script type="text/javascript">
$(function() {
$('#somecontainer a').click(function() {
var id = $(this).attr('href').substring(1);
openNext(id);
return false; // to cancel native click event
});
});
</script>
If you have lots of these on your page, say, over 100, you could also look into jQuery's live
feature to increase performance.
Good luck
You could store the data as an ID for the <tr>
of the row. Then, in your click handler (assuming it's bound to the <tr>
s), call openNext(event.target.id)
精彩评论