Questions tagged «javascript»

有关在ECMAScript(JavaScript / JS)及其各种方言/实现(不包括ActionScript)中进行编程的问题。此标记很少单独使用,但最常与标记[node.js],[jquery],[json]和[html]关联。


8
正则表达式匹配非ASCII字符?
在正则表达式中匹配非ASCII字符的最简单方法是什么?我想匹配输入字符串中的所有单词,但是语言可能不是英语,因此我需要匹配ü,ö,ß和ñ。另外,这是在Javascript / jQuery中,因此任何解决方案都需要适用于此。
237 javascript  jquery  regex 

16
如何使用jQuery或Javascript将货币字符串转换为双精度?
我有一个文本框,其中将包含货币字符串,然后需要将该字符串转换为双精度以对其执行一些操作。 "$1,100.00" → 1100.00 这需要在所有客户端发生。我别无选择,只能将货币字符串保留为输入的货币字符串,但需要将其强制转换/转换为双精度以进行一些数学运算。
237 javascript  jquery 

14
在jest.setTimeout指定的5000ms超时内未调用异步回调
我正在使用puppeteer和jest进行一些前端测试。 我的测试如下所示: describe("Profile Tab Exists and Clickable: /settings/user", () => { test(`Assert that you can click the profile tab`, async () => { await page.waitForSelector(PROFILE.TAB); await page.click(PROFILE.TAB); }, 30000); }); 有时,当我运行测试时,一切都会按预期进行。其他时候,我得到一个错误: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout. at node_modules/jest-jasmine2/build/queue_runner.js:68:21 at Timeout.callback [as …

13
如何最好地确定参数是否未发送到JavaScript函数
现在,我已经看到了两种确定参数是否已传递给JavaScript函数的方法。我想知道一种方法是否比另一种更好,或者一种方法不好用? function Test(argument1, argument2) { if (Test.arguments.length == 1) argument2 = 'blah'; alert(argument2); } Test('test'); 要么 function Test(argument1, argument2) { argument2 = argument2 || 'blah'; alert(argument2); } Test('test'); 据我所知,它们都产生相同的结果,但是我在生产中只使用了第一个。 汤姆提到的另一个选择: function Test(argument1, argument2) { if(argument2 === null) { argument2 = 'blah'; } alert(argument2); } 根据Juan的评论,最好将Tom的建议更改为: function Test(argument1, argument2) { if(argument2 …






30
如何获得数组的第一个元素?
如何从这样的数组中获取第一个元素: var ary = ['first', 'second', 'third', 'fourth', 'fifth']; 我尝试了这个: alert($(ary).first()); 但是它会回来[object Object]。所以我需要从数组中获取第一个元素,它应该是element 'first'。

6
如何将Map键转换为数组?
可以说我有以下地图: let myMap = new Map().set('a', 1).set('b', 2); 我想根据以上内容获得['a','b']。我当前的解决方案似乎是如此漫长而可怕。 let myMap = new Map().set('a', 1).set('b', 2); let keys = []; for (let key of myMap) keys.push(key); console.log(keys); 必须有更好的方法,不是吗?




By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.