JQuery - Open modal for dynamic links
I have several links and I need to open a modal window with a form so the user can upload a image.
I need to send the link ID to this modal window so I can make the correct upload.
I really don't know how to do that because my links have the same Id, otherwise I need to create a modal function for each link.
How do 开发者_StackOverflow中文版I do that?
Thanks in advance.
ID's are supposed to be unique according to html standards. So you can add a dialog to a link based on the class. Which will be best way to do..
Working example here
I don't fully understand what you're trying to do with the links, but nevertheless:
- html IDs must be unique within the document, so if that's the source of your problem, you just need to fix that
- modal dialogs can be created with jQuery UI: http://jqueryui.com/demos/dialog/
You use unique ids for everything i.e.
<sometag id=thisdynid<?php echo your_dynamic_id_in_loop; ?> >
So now you have dynamic HTML ID elements.
Now your jQuery handlers will be coded into your loop as well.
$('#thisdynid<?php echo your_dynamic_id_in_loop; ?>').event.function(){
function code here.
}
Now you have dynamic elements with dynamic event handlers, couldn't be simpler. You can also use the 'name' attribute to fetch the ids to pass through to your php page.
<sometag id="thisdynid<?php echo your_dynamic_id_in_loop; ?>" name="<?php echo your_dynamic_id_in_loop; ?>">
Then:
$.ajax({
url: 'your.php',
method: 'GET',
data: 'ID=' + $(this).attr('name'),
success: function(data) {
etc etc.. hope this helps
精彩评论