草庐IT

documenting

全部标签

javascript - 如何将自定义 jQuery 事件冒泡到 window.document?

我写了一个绝对定位的下拉菜单。当此菜单打开时,我正在触发自定义事件:ps.DropDown.prototype._onOpenComplete=function(){$(this).trigger('MENU_OPEN',[this]);}当我知道要定位哪个ps.DropDown实例时,这非常有效:vardd=newps.DropDown();$(dd).on('MENU_OPEN',fn);但是,如果事件没有停止传播,我希望我的自定义事件冒泡到window.document。例如:vardd=newps.DropDown();$(dd).on('MENU_OPEN',function

javascript - 在 document.ready 中添加 youtube iframe 代码时出现问题

我想在我的$(document).ready()函数中添加youtubeiframeapi代码,但是当我这样做时,播放器似乎没有加载,当我将代码移到document.ready之外时,播放器加载正常.谁能给我任何关于如何在函数内部显示此视频的建议?JS$(document).ready(function(){vartag=document.createElement('script');tag.src="//www.youtube.com/iframe_api";varfirstScriptTag=document.getElementsByTagName('script')[0];f

javascript - 无法在 jquery document.ready 中初始化对象

我有一个名为concept的javascript对象:functionconcept(){this.ConceptId=0;this.Name="";}我正在尝试在jQuerydocument.ready中启动它:$(document).ready(function(){varconcept=newconcept;});它返回一个错误:UncaughtTypeError:conceptisnotaconstructor如果我将对象移动到document.ready中,它就可以工作了。$(document).ready(function(){functionconcept(){this.

javascript - WordPress Revolution slider : Unmuting failed and the element was paused instead because the user didn't interact with the document before

当我遇到以下JavaScript错误(在GoogleChrome中)时,我试图在ThemePunchSliderRevolution5.4.2中自动播放视频:Unmutingfailedandtheelementwaspausedinsteadbecausetheuserdidn'tinteractwiththedocumentbefore.revolution.extension.video.min.js:7 最佳答案 OP的回答:在网上苦苦思索了3天后,我决定打开出现错误的脚本,即:revolution.extension.vi

javascript - $(document).ready(function() 和 $(function() 之间有什么区别?

所以我知道这是做什么的:$(document).ready(function(){//Yourcodehere...});现在我看到人们最近这样做:$(function(){//Yourcodehere...});这两种方式做同样的事情吗?我在这里看到在jquery选择器中声明了一个匿名函数,但实际上从未被调用过,但从页面运行的方式来看,这似乎只是在页面加载时运行。 最佳答案 是的,他们在做同样的事情。当调用的参数是单个函数对象时,$()函数包装$(document).ready()。(编辑以反射(reflect)评论中的问题)

javascript - document.getElementById 是否返回事件的 dom 元素?

JavaScript中的document.getElementById是否返回事件的DOM元素?出于性能原因,我有兴趣知道 最佳答案 标准和“实时”之间的区别通常用于元素的列表。document.getElementById返回对DOM节点的单个对象引用。获取节点后,引用将始终指向同一节点。示例的HTML:以JS为例:varfoo,bar;foo=document.getElementById('foo');//getsthedivbar=document.getElementById('bar');//nullfoo.setAtt

javascript - document.write 真的被弃用了吗?

我看到一些关于document.write被弃用的讨论,但我不确定这些信息的确切来源。IdidlookitupinMDN,但没有任何关于它被弃用的符号..所以现在我有点怀疑。不幸的是,谷歌也没有太大帮助(也许我只是没有使用正确的搜索词)。如果确实已弃用,有人可以将我链接到显示它确实已弃用的适当文档吗? 最佳答案 没有。它通常被认为是不好的做法,几乎与eval一样被滥用。阅读:Whyisdocument.writeconsidereda'badpractice'?引用上面链接问题的一些要点:document.write(hencefo

javascript - Angular 中的 $document 和 $window.document 有什么区别?

我在JSBin中试了下面的代码,第一个可以拿到canvas对象。但是,第二个不能。JSBin:http://jsbin.com/natavejasa/1/edit?html,js,outputvarcanvas=$window.document.getElementById('myCanvas');JSBin:http://jsbin.com/yareb/1/edit?html,js,outputvarcanvas=$document.getElementById('myCanvas');所以我想知道$window.document和$document之间有什么区别。

JavaScript: 'Document' 和 'HTML' 有什么区别

例子:$(document).click(function(){blah});//and$('html').click(function(){blah}); 最佳答案 我会分几个部分来回答这个问题。在JavaScript(不仅仅是jQuery,而是所有JavaScript)中,document关键字是包含HTMLDocument的对象的句柄。您可能会在以下情况下使用此句柄...//Getthecurrentwebaddressalert(document.location.href);当您将文档传递给jQuery时,它会将文档解析为

javascript - 使用自调用匿名函数和 $(document).ready

我最近才了解到自调用匿名函数。我遇到的一些代码片段使用了自调用函数以及$(document).ready。两者同时使用似乎是多余的或毫无意义的。有没有你会使用的情况(function(){$(document).ready();})();对比$(document).ready(function(){(function(){})();});我认为您可能希望立即执行脚本或在加载DOM后执行脚本。我不明白你为什么要同时使用两者。谢谢。 最佳答案 第一个示例肯定有一个用例。如果您在同一页面上加载了其他JS库/脚本,则无法保证它们不会覆盖$变