嗨我有这个代码需要页面中的jquery。
https://jsfiddle.net/sysgn9pe/3/
我使用此代码导入最新的jquery:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
但添加此代码后,我的聊天脚本在控制台上面临问题:
TypeError: $.newWindow is not a function chat-mobi.js:343:0
TypeError: $.updateWindowContentWithAjax is not a function
以及这些代码:
$.newWindow({
id: "register",
title: 'fast signup system' ,
width: 240,
height: 140,
posx: Math.floor(Math.random() * 50) + 150,
posy: Math.floor(Math.random() * 50) + 150,
content: "Password : <br><input type='password' id='regpw' name='regpw'><br>Again : <br><input type='password' id='regpwconfrim' name='regpwconfrim'><br><a href='javascript:;' onclick='register();'>Sign</a>",
statusBar: true,
minimizeButton: false,
maximizeButton: false,
closeButton: true,
draggable: true,
resizeable: true
});
}
另一个:
function updatehistory(){
$.updateWindowContentWithAjax('history','./?history&'+self.ri+"&"+self.rn);
}
在添加jquery 之前,脚本没问题
我有.newWindow的window.js
var jqWindowsEngineZIndex=100;jQuery.extend({newWindow:function(e){var t=0;var n=0;var r={id:"",title:"",width:300,height:200,posx:50,posy:50,content:"",onDragBegin:null,onDragEnd:null,onResizeBegin:null,onResizeEnd:null,onAjaxContentLoaded:null,onWindowClose:null,statusBar:true,minimizeButton:true,maximizeButton:true,closeButton:true,draggable:true,resizeable:true,type:"normal",modal:false};var e=$.extend(r,e);var i="";if(e.id!="")i='id="'+e.id+'"';$modalBackground=$('<div class="modal-background"></div>');$modalBackground.css("z-index","10000");$windowContainer=$("<div "+i+' class="window-container"></div>');$titleBar=$('<div class="window-titleBar"></div>');$titleBar.append('<div class="window-titleBar-leftCorner"></div>');$titleBarContent=$('<div class="window-titleBar-content">'+e.title+"</div>");$titleBar.append($titleBarContent);$titleBar.append('<div class="window-titleBar-rightCorner"></div>');$windowMinimizeButton=$('<div class="window-minimizeButton"></div>');$windowMaximizeButton=$('<div class="window-maximizeButton"></div>');$windowCloseButton=$('<div class="window-closeButton"></div>');$windowContent=$('<div class="window-content"></div>');$windowStatusBar=$('<div class="window-statusBar"></div>');$windowResizeIcon=$('<div class="window-resizeIcon"></div>');if(e.minimizeButton)$titleBar.append($windowMinimizeButton);if(e.maximizeButton)$titleBar.append($windowMaximizeButton);if(e.closeButton)$titleBar.append($windowCloseButton);if(e.resizeable)$windowStatusBar.append($windowResizeIcon);$windowContainer.append($titleBar);$windowContent.append(e.content);$windowContainer.append($windowContent);if(e.statusBar)$windowContainer.append($windowStatusBar);if(e.type==="iframe"){$windowContent.css("overflow","hidden")}var s=function(){document.onselectstart=function(){return false}};var o=function(){document.onselectstart=null};var u=function(t){if(e.modal){t.css("z-index",10001)}else{t.css("z-index",jqWindowsEngineZIndex++)}};var a=function(t,n,r){n=parseInt(n);r=parseInt(r);t.data("lastWidth",n).data("lastHeight",r);t.css("width",n+"px").css("height",r+"px");if(e.type==="iframe"){var i=3,s=2;if($.browser.msie&&$.browser.version<9)i=s=0;t.find("iframe").css("width",n-i+"px").css("height",r-s+"px");t.find("iframe").each(function(){$("#jquery-window-engine-iframe-cover").css({top:$(this).offset().top,left:$(this).offset().left,width:this.offsetWidth,height:this.offsetHeight,position:"absolute",opacity:"0.0001",zIndex:1e4,background:"#444"})})}};var f=function(t,n,r){n=Math.max(0,parseInt(n));r=Math.max(0,parseInt(r));t.data("lastX",n).data("lastY",r);n=n+"px";r=r+"px";t.css("left",n).css("top",r);if(e.type==="iframe"){t.find("iframe").each(function(){$("#jquery-window-engine-iframe-cover").css({top:$(this).offset().top,left:$(this).offset().left,width:this.offsetWidth,height:this.offsetHeight,position:"absolute",opacity:"0.0001",zIndex:1e4,background:"#444"})})}};var l=function(r,i){if(e.draggable){r=r?r:window.event;var s=parseInt(i.css("left"))+(r.clientX-t);var o=parseInt(i.css("top"))+(r.clientY-n);t=r.clientX;n=r.clientY;f(i,s,o)}};var c=function(e,r){e=e?e:window.event;var i=parseInt(r.css("width"));var s=parseInt(r.css("height"));i=i<100?100:i;s=s<50?50:s;var o=i+(e.clientX-t);var u=s+(e.clientY-n);t=e.clientX;n=e.clientY;a(r,o,u)};$titleBarContent.bind("mousedown.jquerywindow",function(r){$obj=$(r.target).parent().parent();u($obj);s();if($obj.data("state")!="maximized"){if(e.type==="iframe"){var i=$('<div id="jquery-window-engine-iframe-cover" ></div>');$obj.find("iframe").each(function(){i.css({top:$(this).offset().top,left:$(this).offset().left,width:this.offsetWidth,height:this.offsetHeight,position:"absolute",opacity:"0.0001",zIndex:1e4,background:"#444"});$("body").append(i)})}r=r?r:window.event;t=r.clientX;n=r.clientY;$(document).bind("mousemove.jquerywindow",function(e){l(e,$obj)});$(document).bind("mouseup.jquerywindow",function(t){if(e.type==="iframe")$("#jquery-window-engine-iframe-cover").remove();if(e.onDragEnd!=null)e.onDragEnd();$(document).unbind("mousemove.jquerywindow");$(document).unbind("mouseup.jquerywindow");o()});if(e.onDragBegin!=null)e.onDragBegin()}else if(e.type==="iframe"){$("#jquery-window-engine-iframe-cover").remove()}return false});$titleBarContent.dblclick(function(e){$obj=$(e.target).parent().parent();$obj.find(".window-maximizeButton").click()});$windowResizeIcon.bind("mousedown.jquerywindow",function(r){$obj=$(r.target).parent().parent();u($obj);s();if($obj.data("state")==="normal"){if(e.type==="iframe"){var i=$('<div id="jquery-window-engine-iframe-cover" ></div>');$obj.find("iframe").each(function(){i.css({top:$(this).offset().top,left:$(this).offset().left,width:this.offsetWidth,height:this.offsetHeight,position:"absolute",opacity:"0.0001",zIndex:1e4,background:"#444"});$("body").append(i)})}r=r?r:window.event;t=r.clientX;n=r.clientY;$(document).bind("mousemove.jquerywindow",function(e){c(e,$obj)});$(document).bind("mouseup.jquerywindow",function(t){if(e.type==="iframe")$("#jquery-window-engine-iframe-cover").remove();if(e.onResizeEnd!=null)e.onResizeEnd();$(document).unbind("mousemove.jquerywindow");$(document).unbind("mouseup.jquerywindow");o()});if(e.onResizeBegin!=null)e.onResizeBegin()}return false});$windowMinimizeButton.bind("click.jquerywindow",function(e){$obj=$(e.target).parent().parent();u($obj);if($obj.data("state")==="minimized"){$obj.data("state","normal");$obj.css("height",$obj.data("lastHeight"));$obj.find(".window-content").slideToggle("slow")}else if($obj.data("state")==="normal"){$obj.data("state","minimized");$obj.find(".window-content").slideToggle("slow",function(){$obj.css("height",0)})}else{$obj.find(".window-maximizeButton").click()}});$windowMaximizeButton.bind("click.jquerywindow",function(t){$obj=$(t.target).parent().parent();u($obj);var n=3,r=2;if($.browser.msie&&$.browser.version<9)n=r=0;if($obj.data("state")==="minimized"){$obj.find(".window-minimizeButton").click()}else if($obj.data("state")==="normal"){$obj.animate({top:"5px",left:"5px",width:$(window).width()-15,height:$(window).height()-45},"slow");if(e.type==="iframe"){$obj.find("iframe").animate({top:"5px",left:"5px",width:$(window).width()-15-n,height:$(window).height()-45-r},"slow")}$obj.data("state","maximized")}else if($obj.data("state")==="maximized"){$obj.animate({top:$obj.data("lastY"),left:$obj.data("lastX"),width:$obj.data("lastWidth"),height:$obj.data("lastHeight")},"slow");if(e.type==="iframe"){$obj.find("iframe").animate({top:$obj.data("lastY"),left:$obj.data("lastX"),width:parseInt($obj.data("lastWidth")-n),height:parseInt($obj.data("lastHeight")-r)},"slow")}$obj.data("state","normal")}});$windowCloseButton.bind("click.jquerywindow",function(t){var n=$(t.target).parent().parent();n.fadeOut();if(e.onWindowClose!=null)e.onWindowClose();if(e.modal){$modalBackground.remove()}});$modalBackground.bind("click.jquerywindow",function(e){$windowCloseButton.click()});$windowContent.click(function(e){u($(e.target).parent())});$windowStatusBar.click(function(e){u($(e.target).parent())});$windowContainer.data("state","normal");$windowContainer.css("display","none");$("body").append($windowContainer);if(e.modal){$("body").append($modalBackground)}$window=$windowContainer;if(!e.draggable)$window.children(".window-titleBar").css("cursor","default");u($window);f($windowContainer,e.posx,e.posy);a($windowContainer,e.width,e.height);$window.fadeIn()},updateWindowContent:function(e,t){$("#"+e+" .window-content").html(t)},updateWindowContentWithAjax:function(e,t,n){n=n===undefined?true:false;$.ajax({url:t,cache:n,dataType:"html",success:function(t){$("#"+e+" .window-content").html(t)}})},moveWindow:function(e,t,n){$obj=$("#"+e);t=parseInt(t);n=parseInt(n);$obj.data("lastX",t).data("lastY",n);t=t+"px";n=n+"px";$obj.css("left",t).css("top",n)},resizeWindow:function(e,t,n){$obj=$("#"+e);t=parseInt(t);n=parseInt(n);$obj.data("lastWidth",t).data("lastHeight",n);t=t+"px";n=n+"px";$obj.css("width",t).css("height",n)},minimizeWindow:function(e){$("#"+e+" .window-minimizeButton").click()},maximizeWindow:function(e){$("#"+e+" .window-maximizeButton").click()},showWindow:function(e){$("#"+e+" .window-closeButton").fadeIn()},hideWindow:function(e){$("#"+e+" .window-closeButton").fadeOut()},closeWindow:function(e){$("#"+e+" .window-closeButton").click()},closeAllWindows:function(){$(".window-container .window-closeButton").click()}})
答案 0 :(得分:0)
jQuery没有$.newWindow
或$.updateWindowContentWithAjax
方法。您似乎还需要包含提供这些方法的plugin。
即,
<script type='text/javascript' src='/path/to/your/js/jquery.windows-engine.js'></script>
答案 1 :(得分:0)
我不认为这些是标准的jQuery函数。你错过了一个插件吗?如果你搜索jQuery api,它们就没有条目:https://api.jquery.com/?s=updateWindowContentWithAjax
答案 2 :(得分:0)
您需要包含this repository中的脚本。 jquery.windows-engine.js
将扩展jQuery,为您提供所需的功能。
<script type='text/javascript' src='https://raw.githubusercontent.com/alexkv/jQuery-Windows-Engine-Plugin/master/jquery.windows-engine.js'></script>
我不要建议将GitHub用作CDN。下载该文件并在本地托管。
此外,这是为jQuery 1.2.6构建的。 jquery-latest.js可能无效。