在体内调用jQuery函数 [英] Calling jquery function in the body

查看:78
本文介绍了在体内调用jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要调用此jquery函数:

I want to call this jquery function:

$(function() {
    if (window.location.href.toLowerCase().indexOf("gamila-secret") < 0) {
        window.location = window.location.href + '?gamila-secret';
    }
});

在我体内的html代码中,因此它将在这里:<body onload="*call the function here*">.
我正在尝试给该函数起一个类似"reloader();"的名称.并在体内调用它,但是我该怎么做呢?

in my html code in the body, so it will be here: <body onload="*call the function here*">.
I'm trying to give the function a name like "reloader();" and call it in the body, but how can I do that?

推荐答案

根据您的选择

以html

<body onload="call()">

在JS中

<script>
function call()
{
  if (location.href.toLowerCase().indexOf("gamila-secret") < 0) {
    location = location.href + '?gamila-secret';
  }
}
</script>

但最好的选择,如果您使用jQuery

以html

<body >
//no need to call function 

在JS中

$(document).ready(function() {
  if (location.href.toLowerCase().indexOf("gamila-secret") < 0) {
    location = location.href + '?gamila-secret';
  }
});

这篇关于在体内调用jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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