Passing (ID) argument from aspx page to javascript function which updates ID somewhere else on the page
So imagine I have a table which is a list of videos, with associated descriptions and links. On the page there is only ever one video shown. When a link is clicked, I want that click to take the ID of the corresponding video and pass it to the video player div, updating whatever video is displayed, ready for play.
VidName | Description | Watch ...and repeat...generated from a foreach in C#
I believe I will need to use开发者_开发技巧
.bind( 'click', [eventData,] handler(eventObject) )
but I am not sure what to put for the second argument - I know I want the ID, but from where? Does the 'Watch' text HAVE to made into a (submit) button or something?
Intinctively I think this is quite simple...sorry for the dumb question if it is one! :)
so why dont you just use the onclick event on the link?
<a id="1" href="javascript:void(0)" onclick="DoSomething(this.id)">Simple's</a>
The way i usually do it is something like this:
<sometag data-id="id-for-the-data"></sometag>
<script>
function onSometagClick() {
$(this).prop('data-id'); // read the id so we can us it
}
$(function(){
$(document.body).delegate('sometag','click',onSometagClick); //handle clicks on all 'sometag' ellements
});
</script>
If you want a less generic answer, please supply some markup :)
The reason i don't use the id attribute is threefold.
1: to separate the markup/DOM from the actual data
2: id attributes are not allowed to start with a number, and my data id's are almost always numbers from a database somewhere.
3: if i need to reference the same data more than once on a page the id attribute is no good since it needs to be unique
精彩评论