[英]how to apply this to all of my pages in jquerymobile
Im using jquerymobile together with codeigniter framework and I'm having a problem 即时通讯与Codeigniter框架一起使用jquerymobile,我遇到了问题
I have this script below and I want it to be trigger in all of my pages. 我下面有这个脚本,我希望在所有页面中都触发它。
<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>
tried replacing the $(function() { to $(document).bind('pageinit', function () { but still doesn't work. The function only fires in my index.php not in the other pages. Please help. 尝试将$(function(){替换为$(document).bind('pageinit',function(){,但仍然无法正常工作。该功能仅在我的index.php中触发,而在其他页面中不触发。请提供帮助。
Try this one. 试试这个。 Prepare an index file with following scripts
使用以下脚本准备索引文件
<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>
now, call this function when you initpage like the following 现在,像下面这样在初始化页面时调用此函数
$('#my_page').live('pageinit',function(event){
start();
}); });
Try this: 尝试这个:
$(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');
If you want to fire in other pages too. 如果您也想在其他页面中触发。 Include the script in all pages.
在所有页面中包含脚本。 Using
使用
<script src="common.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.