Passing information to jqModal
I'm using jqModal inside a Django application. What I would like to do is have a bunch of different links each of which passes a parameter to jqModal to have it call a different ajax url based on the parameter. For example, depending on the ID of what is click on, I want to do something like:
$('#popup').jqm({ajax: '/myapp/objects/' + id, trigger: 'div.modaltrigger'});
Where id is the id of whatever I've clicked on.
Is this possible to do? 开发者_Go百科
Use data attributes of the triggering elements to store your URLs:
<div class="modaltrigger" data-ajax-url="/myapp/objects/108"...
Then use jqModal in the following way:
$('#popup').jqm({ajax: '@data-ajax-url', trigger: 'div.modaltrigger'});
You said you want to change the url depending on ID, so I assume your links look like this
<div id="obj1" class="modaltrigger">foo</div>
<div id="obj2" class="modaltrigger">bar</div>
And you want jqModal to call urls like this
/myapp/objects/obj1
/myapp/objects/obj2
Then this code should work
//must run before first ajax call is made
$('div.modaltrigger').each(function(i, ele) {
ele.title = '/myapp/objects/'+this.id;
});
$('#popup').jqm({
ajax: '@title',
trigger: 'div.modaltrigger'
});
精彩评论