Running JQuery scripts on AJAX loaded content

前端 未结 4 1965
你的背包
你的背包 2020-12-13 07:45

I am using .load() to pull static HTML files onto my main HTML page. The scripts and selectors that I have written exist within:

$(document).ready(function()         


        
4条回答
  •  猫巷女王i
    2020-12-13 08:12

    There are more than one option:

    1. you can add initialization scripts [ $(this).click... ] into callback function of $.load()
    2. you can use $.live(), which creates handlers even for dynamically loaded/created objects.

    More here:
    callback: http://api.jquery.com/load/ (notice the "complete()" function)
    bind: http://api.jquery.com/live/

    Edit: My mistake, it was live(), not bind(), thank you guys

提交回复
热议问题