The right way parse html to jQuery object

I want to parse a html string to jQuery object then find an element by ID. I tried 3 ways bellow, but only the last works. I don't know why the others not works? var html = "<html><body><div id='main'></div></body></html>"; // Not work, return 0 console.log($(html).find('#main').length); // Not work, return 0 console.log($($.parseHTML(html)).find('#ma

正确的方法解析html到jQuery对象

我想解析一个html字符串到jQuery对象,然后通过ID找到一个元素。 我尝试了3种方法,但只有最后的作品。 我不知道为什么其他人不工作? var html = "<html><body><div id='main'></div></body></html>"; // Not work, return 0 console.log($(html).find('#main').length); // Not work, return 0 console.log($($.parseHTML(html)).find('#main').length); // Works, return 1 consol

How to check if a string contain specific words

$a = 'how are you'; if (strpos($a,'are') !== false) { echo 'true'; } 在PHP中,我们可以使用上面的代码来检查一个字符串是否包含特定的单词,但我怎样才能在JavaScript / jQuery中执行相同的功能? If you are looking for exact words and don't want it to match things like "nightmare" (which is probably what you need), you can use a regex: /bareb/gi b = word boundary g = global i = case i

如何检查一个字符串是否包含特定的单词

$a = 'how are you'; if (strpos($a,'are') !== false) { echo 'true'; } 在PHP中,我们可以使用上面的代码来检查一个字符串是否包含特定的单词,但我怎样才能在JavaScript / jQuery中执行相同的功能? 如果你正在寻找确切的单词并且不希望它匹配诸如“噩梦”(这可能是你需要的),你可以使用正则表达式: /bareb/gi b = word boundary g = global i = case insensitive (if needed) 如果你只是想找到字符“是”,然后使用in

How to tell if a string contains a certain character in JavaScript?

I have a page with a textbox where a user is supposed to enter a 24 character (letters and numbers, case insensitive) registration code. I used maxlength to limit the user to entering 24 characters. The registration codes are typically given as groups of characters separated by dashes, but I would like for the user to enter the codes without the dashes. How can I write my JavaScript code wit

如何判断一个字符串是否包含JavaScript中的某个字符?

我有一个带有文本框的页面,用户应输入24个字符(字母和数字,不区分大小写)的注册码。 我用maxlength限制用户输入24个字符。 注册代码通常以用破折号分隔的字符组的形式给出,但我希望用户输入没有破折号的代码。 如何在没有jQuery的情况下编写我的JavaScript代码来检查用户输入的给定字符串是否不包含破折号,或者更好的是只包含字母数字字符? 在your_string找到“hello” if (your_string.indexOf('hello') > -1) {

Making javascript search innerHTML?

This question already has an answer here: How do I check if string contains substring? [duplicate] 13 answers var didIFindIt = document.getElementById(“test”)。innerHTML.match(/ MySearchTerm / g).length> 0;

让javascript搜索innerHTML?

这个问题在这里已经有了答案: 如何检查字符串是否包含子字符串? [复制] 13个回答 var didIFindIt = document.getElementById(“test”)。innerHTML.match(/ MySearchTerm / g).length> 0;

JavaScript getter for all properties

Long story short: I'm in a situation where I'd like a PHP-style getter, but in JavaScript. My JavaScript is running in Firefox only, so Mozilla specific JS is OK by me. The only way I can find to make a JS getter requires specifying its name, but I'd like to define a getter for all possible names. I'm not sure if this is possible, but I'd very much like to know. The clo

所有属性的JavaScript getter

长话短说:我处于一种我喜欢PHP风格的getter的情况,但在JavaScript中。 我的JavaScript只在Firefox中运行,所以Mozilla特定的JS对我来说可以。 我可以找到的唯一方法是创建一个JS getter,它需要指定它的名字,但是我想为所有可能的名称定义一个getter。 我不确定这是否可行,但我很想知道。 您可以找到最接近的__noSuchMethod__,它是PHP的__call()的等价物。 不幸的是,没有相当于__get / __ set,这是一个耻辱,

Http response header not getting modified in firefox extension always

I am modifying the inlinedisposition extension of firefox. Here is the code snippet which actually modifies the header: _httpResponse: function( chan ) { var disp = ""; try { chan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); disp = chan.getResponseHeader("Content-Disposition"); } catch (e) { } if (chan.loadFlags & Components.interfaces.nsIC

Http响应标题不会在firefox扩展中被修改

我正在修改firefox的inlineisposition扩展。 以下是实际修改标题的代码片段: _httpResponse: function( chan ) { var disp = ""; try { chan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); disp = chan.getResponseHeader("Content-Disposition"); } catch (e) { } if (chan.loadFlags & Components.interfaces.nsIChannel.LOAD_DOCUMENT_URI && this._re.te

Modifying HTTP response headers in Firefox

Does anyone know if Firefox extensions are allowed to modify HTTP response headers? For example, can an extension remove the x-frame-options header to let the page load in an iframe? Thanks S. Wong is correct. Modify Headers supports modification of request headers only at present. However, I am looking at supporting response headers for a future version. I think the best firefox addon f

在Firefox中修改HTTP响应标头

有谁知道Firefox扩展是否允许修改HTTP响应头? 例如,扩展是否可以删除x-frame-options标头以使页面加载到iframe中? 谢谢 S. Wong是正确的。 只有目前修改头才支持修改请求头。 但是,我正在寻找支持未来版本的响应标头。 我认为用于修改标题的最好的Firefox插件是TamperData: https://addons.mozilla.org/en-US/firefox/addon/966/ 有一个修改响应插件仅限于Content-Type,但应该适用于所有(大多数)其他人。

javascript

I'm trying to implement the basic XHR listener as described on "Ashita" however, when loading firefox with the extension I recieve this error on whenever a page tries to load which prevents anything from loading: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIBinaryInputStream.readBytes]" nsresult: "0x80004

JavaScript的

我试图按照“Ashita”中描述的方式实现基本的XHR侦听器,但是,当加载Firefox的扩展时,每当页面尝试加载时都会收到此错误,从而阻止任何加载: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIBinaryInputStream.readBytes]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://xhrlogger/content/overlay.j

Altering HTTP Responses in Firefox Extension

How can I alter the HTTP response body in a Firefox extension? I have setup an http-on-examine-response observer and an nsIStreamListener object with the code below. After I get the data, parse it, and alter it, how do I push the altered response back to the firefox browser? For example, let's say I go to Google.com with my extension enabled, the extension should intercept the response and

在Firefox扩展中改变HTTP响应

如何在Firefox扩展中更改HTTP响应正文? 我使用下面的代码设置了一个http-on-examine-response观察者和一个nsIStreamListener对象。 获取数据,解析并修改数据后,如何将更改的响应返回给Firefox浏览器? 例如,假设我在启用了我的扩展程序的情况下访问Google.com,扩展程序应拦截响应并将每次发生的“谷歌”更改为“护目镜”。 所以当页面加载时,用户会在任何地方看到“护目镜”。 function TmSteroidsObserver() { this.regis

How to check if a string "StartsWith" another string?

How would I write the equivalent of C#'s String.StartsWith in JavaScript? var haystack = 'hello world'; var needle = 'he'; //haystack.startsWith(needle) == true Note: This is an old question, and as pointed out in the comments ECMAScript 2015 (ES6) introduced the .startsWith method. However, at the time of writing this update (2015) browser support is far from complete. You can use ECMA

如何检查一个字符串“StartsWith”是否是另一个字符串?

我如何在JavaScript中编写相当于C#的String.StartsWith ? var haystack = 'hello world'; var needle = 'he'; //haystack.startsWith(needle) == true 注意:这是一个老问题,正如ECMAScript 2015(ES6)中引入.startsWith方法的评论中指出的那样。 但是,在撰写此更新(2015年)时,浏览器支持还远未完成。 您可以使用ECMAScript 6的String.prototype.startsWith()方法,但它尚未在所有浏览器中受支持。 您需要使用Shi