Hi All
I use jQuery dynamically create tabs, but each time I click one tab, it will reload the target URL again. How should I disable the reload behavior unless I want it reloads again?
thanks a lot.
views:
127answers:
3
+4
A:
Use event.preventDefault()
:
$('a.tab').click(function(event) {
event.preventDefault(); // this is the key
// your code here
});
Edit: Regarding your comment – just set cache
to true:
$(document).ready(function() {
$apTabs = $("#apTabs").tabs({
// ...
cache: true, // this does the magic
// ...
});
});
moff
2009-04-21 12:59:21
thanks for your quick answer :-), but disable default event will cause my selected tab not show. I need show content retrieved from initial load, just want preventing it from asking content from server again. Thank you very much.
Matt
2009-04-21 13:16:34
Thanks for the point. set "cache" to true did the magic.
Matt
2009-04-22 00:51:47
A:
Post my code for your reference:
$(document).ready(function() {
$apTabs = $("#apTabs").tabs({
ajaxOptions: { async: true },
cache:false,
add: function(event, ui) {
//immdeiately select the new created one
$apTabs.tabs('select', '#' + ui.panel.id);
}
});
});
<div id="apTabs">
<ul>
<li></li>
</ul>
<div></div>
</div>
Matt
2009-04-21 13:25:44