初始化脚本 [英] Initialize script

查看:96
本文介绍了初始化脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要学习如何初始化脚本。我有谷歌它,但不是真的不明白。

I need to learn how to initialize scripts. I have google it but dont dont really understand it.

现在我有一个div中的切换脚本,整个div被加载到另一个页面。切换脚本可以工作,但不能在加载时工作。

Right now I have a toggle-script that is in a div, that entire div gets loaded in to another page. The toggle scripts work, but not when its loaded in.

$(".class").click(function () {
$(this).toggleClass("add_class");
});

如果有人有时间,你能解释一下如何初始化这个脚本吗?

If somebody have time, can you explain to me how to initialize this script?

谢谢。

推荐答案

您应该将此脚本放入document.ready调用中。

You should put this script inside a document.ready call.

例如。

$(document).ready(function() {
    //Put your code here
});

如果我误解了你的问题,你的意思是:

If I misunderstood your question and what you actually mean is:

通过AJAX调用加载脚本后如何执行脚本。
然后看到这个问题:在jQuery Ajax调用后执行脚本

How do you execute the script after you load it in through an AJAX call. Then see this question: executing script after jQuery Ajax Call

这篇关于初始化脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆