Tag: JavaScript

关联数组与javascript中的对象

在我的脚本中,需要创build一个哈希表,我在谷歌search这个。 大多数人都在为此推荐JavaScript对象。 问题是,散列表中的一些键有“。” 在他们中。 我可以用关联数组轻松创build这些键。 我不明白为什么联合数组是不好的。 在我看到的网站中提到的第一件事是长度属性。 我来自Perl背景,我用哈希。 最常见的用途是从键中获取值,检查键是否存在,删除键值对,添加键值对。 如果这些是我的常见用法,我可以安全地使用关联数组吗?

将camelCaseText转换为骆驼案例文本

如何在Javascript中将string转换为“HelloThere”或“HelloThere”以“Hello There”

您可以通过脚本确定Chrome是否处于隐身模式吗?

是否可以通过脚本确定Google Chrome是否处于隐身模式? 编辑: 我其实意思是可以通过用户脚本,但答案假设JavaScript正在运行在网页上。 关于用户脚本,我在这里重新提出了这个问题。

从XmlHttpRequest.responseJSONparsingJSON

我试图parsingjavscript中的一个.json响应。 我通过XmlHttpRequest获取JSON。 var req = new XMLHttpRequest; req.overrideMimeType("application/json"); req.open('GET', BITLY_CREATE_API + encodeURIComponent(url) + BITLY_API_LOGIN, true); var target = this; req.onload = function() {target.parseJSON(req, url)}; req.send(null); parseJSON: function(req, url) { if (req.status == 200) { var jsonResponse = req.responseJSON; var bitlyUrl = jsonResponse.results[url].shortUrl; } 我在一个Firefox插件。 当我运行时,我得到的错误“jsonResponse是未定义的”行var bitlyUrl = jsonResponse.results[url].shortUrl; 。 我在这里parsingJSON时做错了什么? 或者这个代码有什么问题?

screen.availHeight和window.height()之间的区别

我在我的浏览器(Firefox)上执行以下Javascript。 console.debug(“Screen height =”+ screen.availHeight ); //输出770 console.debug(“Window Height =”+ $(window).height() ); //输出210 (我也使用jQuery) 两者有什么区别? 770像素和210毫米? 同样,当我写$(document).height()和$(window).height() ,有一个区别。 是什么原因?

Twitter引导模态input字段焦点

我从例子中有下面的模式forms: <!– Button to trigger modal –> <a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a> <!– Modal –> <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Modal header</h3> </div> <div class="modal-body"> Enter something: <input type="text" id="myInput"> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button class="btn btn-primary">Save changes</button> […]

Javascript:在同一窗口中打开新页面

有没有一种简单的方法来修改这段代码,以便在SAME窗口中打开目标URL? <a href="javascript:q=(document.location.href);void(open('http://example.com/submit.php?url='+escape(q),'','resizable,location,menubar,toolbar,scrollbars,status'));">click here</a>“

如何在JavaScript中的“:”之前删除部分string?

如果我有一个string“Abc:Lorem ipsum sit amet”,如何使用javascript / jQuery删除“:”之前的string,包括“:”。 例如,上面的string将变成:“Lorem ipsum sit amet”。

重新排列数组

说,我有一个数组,看起来像这样: var playlist = [ {artist:"Herbie Hancock", title:"Thrust"}, {artist:"Lalo Schifrin", title:"Shifting Gears"}, {artist:"Faze-O", title:"Riding High"} ]; 我怎样才能移动一个元素到另一个位置? 我想举个例子, {artist:"Lalo Schifrin", title:"Shifting Gears"}到最后。 我尝试使用拼接,像这样: var tmp = playlist.splice(2,1); playlist.splice(2,0,tmp); 但它不起作用。

删除HTML表格中的所有行

如何删除HTML表中除了<th>之外的所有行,并且没有循环遍历表中的所有行? 我有一个非常巨大的表,我不想冻结用户界面,而我循环行删除它们