tags:

views:

127

answers:

3

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.

+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
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
Thanks for the point. set "cache" to true did the magic.
Matt
+1  A: 
$('#tabs').click(function(){
  // code
  return false;
});
draco
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