草庐IT

DOCUMENT

全部标签

javascript - 哪个更好 - Ext.get() 或 document.getElementById()

Ext.get()和document.getElementById()在性能方面有什么区别?Ext.get()会因为内部调用document.getElementById()而变慢吗?或者使用Ext.get()有什么特别的优势吗? 最佳答案 Ext.get相对于getElementById的主要优势在于它返回给您一个Ext.Element实例。该实例不仅包含getElementById将为您提供的DOM节点引用,而且还对其进行了显着扩展-提供了一套便捷的方法、事件规范化和消除跨浏览器差异的方法。从表面上看,getElementByI

javascript - 屏幕宽度与可见部分

我对JavaScript有一个小问题,为了获得屏幕宽度,我们使用screen.width返回整体屏幕分辨率,是否有一个命令来获取浏览器可见部分的分辨率,比如当浏览器不可见时最大化? 最佳答案 functionwidth(){returnwindow.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0;}functionheight(){returnwindow.innerHeight||document.documentElem

JavaScript 将 document.write 保存在一个变量中并调用它

我正在尝试将document.write作为对变量的引用进行传递:例子:varf=document.write//thenf('test');它与警报一起使用。为什么它不适用于document.write? 最佳答案 因为alert不关心this是什么(alert是全局的)和document.write确实如此(它需要知道它正在写入哪个文档)。如果你想要一个包装器,那么写一个快捷函数。functionf(str){document.write(str);}...然后去为调用变量f仪式地开膛破肚。Self-describing是好的代

javascript - 在javascript中查找数组的总和

这个问题在这里已经有了答案:HowtoforceJStodomathinsteadofputtingtwostringstogether[duplicate](11个答案)关闭7年前。我必须为学校编写6个小的JavaScript脚本,除了这个,我已经让它们全部工作了。functioncalculate(){varnumbers=[document.getElementById("num_one").value,document.getElementById("num_two").value,document.getElementById("num_three").value];vars

javascript - $(document).height() 和 $(window).height() 有什么区别

(希望它不是重复的,因为我在搜索和谷歌搜索时没有找到它)当滚动条到达后一个div的底部时,我试图找到如何在某些固定高度的div('#div')中进行检测。我应该使用$(document).height()和$(window).height()来检测这个事件吗?编辑:我的div是固定高度的,我设置了自动滚动,那么如何处理呢?如果我想使用$('#div').height(),这个高度是固定的.... 最佳答案 在.height()文档:$(window).height();//returnsheightofbrowserviewport

javascript - 为什么 chrome 不运行这个 javascript

当我在Chrome(版本2)中运行它时,它不会返回字符串,但它可以在Firefox(版本3)中运行。这是为什么?functiondisp_prompt(){varname=prompt("Pleaseenteryourname","HarryPotter");if(name!=null&&name!=""){document.write("Hello"+name+"!Howareyoutoday?");}} 最佳答案 要将内容附加到文档,您应该只在-block解析阶段调用document.write()。如果您调用document.

javascript - window.top.document.body.scrollTop 在 Chrome 或 FireFox 中不工作

我有下面的代码可以打开一个模态窗口。这适用于IE8,但不适用于Chrome或FF。我是跨浏览器功能领域的新手。functionShowModal(WindowID,FramesetID){window.onscroll=function(){window.top.document.getElementById(WindowID).style.top=window.top.document.body.scrollTop;};window.top.document.getElementById(WindowID).style.display="block";window.top.docum

javascript - JQuery History.js 插件不替换 HTML4 和 HTML5 浏览器中一页的状态

我正在使用JQueryHistory.jsplugin在HTML5浏览器中启用HistoryAPI并在HTML4浏览器中模拟。我正在使用Ajaxifyscript实现这个插件。我稍微更改了此脚本,如下所示:varHistory,$,document;functionPrepareVariables(){History=window.History,$=window.jQuery,document=window.document;}functionInitHistory(){//PrepareVariablesvar/*ApplicationSpecificVariables*///co

javascript - 如何在 OpenCart 中延迟或异步 javascript

我有OpenCart应用程序。Javascripts加载在路径'/catalog/controller//settings.php内的settings.php中,代码类似:$this->document->addScript('catalog/view/theme//lib/lazy/jquery.lazy.1.6.min.js');$this->journal2->minifier->addScript('catalog/view/theme//lib/actual/jquery.actual.min.js','header');$this->journal2->minifier->

JavaScript - 创建元素并设置属性

我有这些函数来创建元素和更改它们的属性。你能给我一个关于如何修改它们的建议吗?functioncreate(elem){returndocument.createElementNS?document.createElementNS("http://www.w3.org/1999/xhtml",elem):document.createElement(elem);}functionattr(elem,name,value){if(!name||name.constructor!=String)return"";name={"for":"htmlFor","class":"classNam