首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js执行jquery解决方法

2012-09-12 
js执行jquery高手看这标题会不会感觉无奈..jquery本来就是javascript嘛。下边是菜鸟的问题,js执行不到jquer

js执行jquery
高手看这标题会不会感觉无奈.. jquery本来就是javascript嘛。
下边是菜鸟的问题, js执行不到jquery里的动作

a.html 是jquery

HTML code
<javascript>$(function()){ function hello(){                   alert('123');}……省略好多function……</javascript>


b.html 是js
HTML code
parent.window.hello();


以上的代码,a.html用js的话是可以执行的, 但改用jquery就不行了, jquery 一开始的$(function)是指在网页DOM结构完成了执行的, 据说这样 hello()就不是一个被绑定的函数,所以不被执行, 那怎样才能让b页面执行到a页面的动作呢

[解决办法]
我晕死过去,你自己代码里面N多错误呀,我以为你之前是可以运行的呢。。。。
JScript code
var MusicBox=function(){    this.prevCache=-1;     this.index=0;    this.currentIndex=this.index;    this.data;//在init中初始化时赋值     this.len=0;//在init中初始化时赋值         this.show=function(cIndex,pIndex){        $("#player").attr("src","player.php?u="+this.data.eq(cIndex).attr("title")+'&ms='+this.data.eq(cIndex).attr("target"));        $("#now_playing").html(this.data.eq(cIndex).attr("target"));        $(document).attr("title", this.data.eq(cIndex).attr("target"));        this.currentIndex=cIndex;        if(pIndex!==undefined){            $(".playerpanel-prev-song-video img").attr("src",this.data.eq(pIndex).attr("href"));             $(".tooltip a").html("&nbsp;&nbsp;"+this.data.eq(pIndex).attr("target")+"&nbsp;&nbsp;");            $("#playerpanel-prev-song").fadeIn(200).animate({left:"0"},2000);        }else{            $("#playerpanel-prev-song").animate({left:"153px"},2000).fadeOut(200);        }    };    this.prevsong=function(){        if(this.prevCache==-1){return}        this.show(this.prevCache);        this.prevCache=-1;    };    this.nextsong=function(){        this.prevCache=this.currentIndex;        this.index++;        this.index%=this.len;        this.show(this.index,this.prevCache);    };    this.init=function(){        this.data=$("#playlist a");        this.len=this.data.size();        $("#playerpanel-prev-song").hover(            function (){                $(".playerpanel-prev-song-overlay").fadeIn(300);                $(".tooltip").css("display","block");            },            function (){                $(".playerpanel-prev-song-overlay").fadeOut(300);                $(".tooltip").css("display","none");            }        );         this.show(this.index);        var _that=this;        $("#prevsong").click(function(){_that.prevsong()});        $("#nextsong").click(function(){_that.nextsong()});        $("#playerpanel-prev-song").click(function(){_that.prevsong()});    }}var myBox=new MusicBox();//顺序不能乱,这个必须在匿名函数的外部$(function(){    myBox.init();//初始化时必须在匿名函数的内容部}) 

热点排行