Javascript 如何将此应用于jquerymobile中的所有页面

Javascript 如何将此应用于jquerymobile中的所有页面,javascript,jquery,codeigniter,jquery-mobile,Javascript,Jquery,Codeigniter,Jquery Mobile,我正在使用jquerymobile和codeigniter框架,我遇到了一个问题 我有这个脚本下面,我希望它是触发在我的所有网页 <script type="text/javascript"> var i = 0; $(function() { $("#h1").hide(); $("#h2").hide(); $("#h3").hide(); <? if ($account_type !=

我正在使用jquerymobile和codeigniter框架,我遇到了一个问题

我有这个脚本下面,我希望它是触发在我的所有网页

<script type="text/javascript">
        var i = 0;
    $(function() {
        $("#h1").hide();
        $("#h2").hide();
        $("#h3").hide();
        <? if ($account_type != 'prepaid' && $account_type != 'PREPAID') : ?>
            $("#h4").hide();
        <? endif ?>
        head();
        setInterval('head()',2000);
    });

        function head()
        {
            i++;
            if (i==1) h1();
            if (i==2) h2();
            <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
                if (i==3){ h3(); i=0; }
            <? else : ?>
                if (i==3) h3();
                if (i==4){ h4(); i=0; }
            <? endif ?>
        }

        function h1()
        {
            <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
                $("#h3").hide();
            <? else : ?>
                $("#h4").hide();
            <? endif ?>
            $("#h1").fadeIn().delay(1000);
            //h2();
        }

        function h2()
        {
            $("#h1").hide();
            $("#h2").fadeIn().delay(1000);
        }

        function h3()
        {
            $("#h2").hide();
            $("#h3").fadeIn().delay(1000);
        }

        function h4()
        {
            $("#h3").hide();
            $("#h4").fadeIn().delay(1000);
        }

    </script>

var i=0;
$(函数(){
$(“#h1”).hide();
$(“#h2”).hide();
$(“#h3”).hide();
$(“#h4”).hide();
头();
setInterval('head()',2000);
});
职能主管()
{
i++;
如果(i==1)h1();
如果(i==2)h2();
如果(i==3){h3();i=0;}
如果(i==3)h3();
如果(i==4){h4();i=0;}
}
函数h1()
{
$(“#h3”).hide();
$(“#h4”).hide();
$(“#h1”).fadeIn().delay(1000);
//h2();
}
函数h2()
{
$(“#h1”).hide();
$(“#h2”).fadeIn().delay(1000);
}
函数h3()
{
$(“#h2”).hide();
$(“#h3”).fadeIn().delay(1000);
}
函数h4()
{
$(“#h3”).hide();
$(“#h4”).fadeIn().delay(1000);
}
已尝试将$(function(){替换为$(document).bind('pageinit',function(){但仍不起作用。该函数仅在my index.php中启动,而不在其他页面中启动。请提供帮助。

尝试此函数。 使用以下脚本准备索引文件

<script type="text/javascript">
var i = 0;
$(function() {
    start();        
});

function start(){

    $("#h1").hide();
    $("#h2").hide();
    $("#h3").hide();
    <? if ($account_type != 'prepaid' && $account_type != 'PREPAID') : ?>
        $("#h4").hide();
    <? endif ?>
    head();
    setInterval('head()',2000);
}

    function head()
    {
        i++;
        if (i==1) h1();
        if (i==2) h2();
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            if (i==3){ h3(); i=0; }
        <? else : ?>
            if (i==3) h3();
            if (i==4){ h4(); i=0; }
        <? endif ?>
    }

    function h1()
    {
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            $("#h3").hide();
        <? else : ?>
            $("#h4").hide();
        <? endif ?>
        $("#h1").fadeIn().delay(1000);
        //h2();
    }

    function h2()
    {
        $("#h1").hide();
        $("#h2").fadeIn().delay(1000);
    }

    function h3()
    {
        $("#h2").hide();
        $("#h3").fadeIn().delay(1000);
    }

    function h4()
    {
        $("#h3").hide();
        $("#h4").fadeIn().delay(1000);
    }

</script>
})试试这个。 使用以下脚本准备索引文件

<script type="text/javascript">
var i = 0;
$(function() {
    start();        
});

function start(){

    $("#h1").hide();
    $("#h2").hide();
    $("#h3").hide();
    <? if ($account_type != 'prepaid' && $account_type != 'PREPAID') : ?>
        $("#h4").hide();
    <? endif ?>
    head();
    setInterval('head()',2000);
}

    function head()
    {
        i++;
        if (i==1) h1();
        if (i==2) h2();
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            if (i==3){ h3(); i=0; }
        <? else : ?>
            if (i==3) h3();
            if (i==4){ h4(); i=0; }
        <? endif ?>
    }

    function h1()
    {
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            $("#h3").hide();
        <? else : ?>
            $("#h4").hide();
        <? endif ?>
        $("#h1").fadeIn().delay(1000);
        //h2();
    }

    function h2()
    {
        $("#h1").hide();
        $("#h2").fadeIn().delay(1000);
    }

    function h3()
    {
        $("#h2").hide();
        $("#h3").fadeIn().delay(1000);
    }

    function h4()
    {
        $("#h3").hide();
        $("#h4").fadeIn().delay(1000);
    }

</script>
}))

试试这个:

$(document).bind('mobileinit', function () {
    var i = 0;

    $(function() {
        $("#h1").hide();
        $("#h2").hide();
        $("#h3").hide();
        <? if ($account_type != 'prepaid' && $account_type != 'PREPAID') : ?>
            $("#h4").hide();
        <? endif ?>
        head();
        setInterval('head()',2000);
    });

    function head()
    {
        i++;
        if (i==1) h1();
        if (i==2) h2();
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            if (i==3){ h3(); i=0; }
        <? else : ?>
            if (i==3) h3();
            if (i==4){ h4(); i=0; }
        <? endif ?>
    }

    function h1()
    {
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            $("#h3").hide();
        <? else : ?>
            $("#h4").hide();
        <? endif ?>
        $("#h1").fadeIn().delay(1000);
        //h2();
    }

    function h2()
    {
        $("#h1").hide();
        $("#h2").fadeIn().delay(1000);
    }

    function h3()
    {
        $("#h2").hide();
        $("#h3").fadeIn().delay(1000);
    }

    function h4()
    {
        $("#h3").hide();
        $("#h4").fadeIn().delay(1000);
    }
}).trigger('mobileinit');
$(document).bind('mobileinit',function(){
var i=0;
$(函数(){
$(“#h1”).hide();
$(“#h2”).hide();
$(“#h3”).hide();
$(“#h4”).hide();
头();
setInterval('head()',2000);
});
职能主管()
{
i++;
如果(i==1)h1();
如果(i==2)h2();
如果(i==3){h3();i=0;}
如果(i==3)h3();
如果(i==4){h4();i=0;}
}
函数h1()
{
$(“#h3”).hide();
$(“#h4”).hide();
$(“#h1”).fadeIn().delay(1000);
//h2();
}
函数h2()
{
$(“#h1”).hide();
$(“#h2”).fadeIn().delay(1000);
}
函数h3()
{
$(“#h2”).hide();
$(“#h3”).fadeIn().delay(1000);
}
函数h4()
{
$(“#h3”).hide();
$(“#h4”).fadeIn().delay(1000);
}
}).触发器(“mobileinit”);
试试这个:

$(document).bind('mobileinit', function () {
    var i = 0;

    $(function() {
        $("#h1").hide();
        $("#h2").hide();
        $("#h3").hide();
        <? if ($account_type != 'prepaid' && $account_type != 'PREPAID') : ?>
            $("#h4").hide();
        <? endif ?>
        head();
        setInterval('head()',2000);
    });

    function head()
    {
        i++;
        if (i==1) h1();
        if (i==2) h2();
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            if (i==3){ h3(); i=0; }
        <? else : ?>
            if (i==3) h3();
            if (i==4){ h4(); i=0; }
        <? endif ?>
    }

    function h1()
    {
        <? if ($account_type == 'prepaid' || $account_type == 'PREPAID') : ?>
            $("#h3").hide();
        <? else : ?>
            $("#h4").hide();
        <? endif ?>
        $("#h1").fadeIn().delay(1000);
        //h2();
    }

    function h2()
    {
        $("#h1").hide();
        $("#h2").fadeIn().delay(1000);
    }

    function h3()
    {
        $("#h2").hide();
        $("#h3").fadeIn().delay(1000);
    }

    function h4()
    {
        $("#h3").hide();
        $("#h4").fadeIn().delay(1000);
    }
}).trigger('mobileinit');
$(document).bind('mobileinit',function(){
var i=0;
$(函数(){
$(“#h1”).hide();
$(“#h2”).hide();
$(“#h3”).hide();
$(“#h4”).hide();
头();
setInterval('head()',2000);
});
职能主管()
{
i++;
如果(i==1)h1();
如果(i==2)h2();
如果(i==3){h3();i=0;}
如果(i==3)h3();
如果(i==4){h4();i=0;}
}
函数h1()
{
$(“#h3”).hide();
$(“#h4”).hide();
$(“#h1”).fadeIn().delay(1000);
//h2();
}
函数h2()
{
$(“#h1”).hide();
$(“#h2”).fadeIn().delay(1000);
}
函数h3()
{
$(“#h2”).hide();
$(“#h3”).fadeIn().delay(1000);
}
函数h4()
{
$(“#h3”).hide();
$(“#h4”).fadeIn().delay(1000);
}
}).触发器(“mobileinit”);

如果您还想在其他页面中启动。在所有页面中包含脚本。使用

<script src="common.js"></script>

如果您还想在其他页面中启动。在所有页面中包含脚本。使用

<script src="common.js"></script>


javascript是否存在于所有页面中?没有,但我已将其添加到头文件中。我不知道“将其添加到头文件”是什么意思。如果代码实际包含在每个页面中,它将只在每个页面中执行。javascript是否存在于所有页面中?没有,但我已将其添加到头文件中。我不知道“将其添加到头文件”是什么意思。只有当代码实际包含在每个页面中时,它才会在每个页面中执行。