Execute php function only when clicked (wordpress)

后端 未结 3 1752
自闭症患者
自闭症患者 2021-01-17 02:17

For one of my wordpress site php files, I have the following code:

  
Items
3条回答
  •  时光说笑
    2021-01-17 02:42

    I think the easiest solution for you would be to use the jQuery load() function. It is the easiest way to achieve what you describe. The only issue that when someone clicks the header, there will be a delay to get the subitems as they do not exist yet (which would be the case for any situation where you delay the load.

    HTML:

      
      

    JS:

    $(function () { 
         //wait for the page to finish loading
       $('#items_id').click (function (e){
         //watch for the items header to be clicked
       e.preventDefault();
        //prevent it from opening a link
        $('#tab1').load('tab1.php');
       //load the tab1.php file, or whatever file INTO the div
       });
    })
    

提交回复
热议问题