I would like to format a price in JavaScript. I'd like a function which takes a float as an argument and returns a string formatted like this: "$ 2,500.00" What's the best way to do this? You can use: var profits=2489.8237 profits.toFixed(3) //returns 2489.824 (round up) profits.toFixed(2) //returns 2489.82 profits.toFixed(7) //returns 2489.8237000 (padding) Then you can a
我想用JavaScript格式化一个价格。 我想要一个函数,它将float作为参数并返回一个格式如下所示的string : "$ 2,500.00" 什么是最好的方法来做到这一点? 您可以使用: var profits=2489.8237 profits.toFixed(3) //returns 2489.824 (round up) profits.toFixed(2) //returns 2489.82 profits.toFixed(7) //returns 2489.8237000 (padding) 然后你可以添加'$'的符号。 如果你需要','为数千
I would like to access listdata.svc (a sharepoint service) located on domainA.contoso.com from a web application located on domainB.contoso.com - Authentication seems to be an issue. When attempting to access ListData.svc via a JQuery Ajax call, with CORS enabled, the server returns 401. If I run the same Query from an .htm page which I execute from inside of SharePoint, the call works fine, si
我想从位于domainB.contoso.com上的Web应用程序访问位于domainA.contoso.com上的listdata.svc(一种共享点服务) - 认证似乎是一个问题。 当试图通过JQuery Ajax调用来访问ListData.svc时,如果启用CORS,服务器将返回401.如果我从.SharePoint内部执行的.htm页面运行相同的查询,调用将正常工作,因为该域是一样。 SharePoint正在使用关闭匿名身份验证的NTLM--我认为401是Windows身份验证没有被传递到SharePoint服务器的结果
I am wondering if node.js is good for server side application wich is not actually communicating with browser, or browser communication is just an additional part of whole app used rather for management. The idea is simple: Server receives high amount of UDP traffic with short messages containing user data from another server. For each message app performs DB lookup and filter out messages
我想知道node.js是否适合服务器端应用程序,但实际上并不是与浏览器通信,或者浏览器通信只是整个应用程序的一部分,而不是用于管理。 这个想法很简单: 服务器通过包含来自其他服务器的用户数据的短消息接收大量的UDP流量。 对于每个消息应用程序执行数据库查找并使用不在白名单上的userid过滤掉消息。 过滤的消息将被处理,导致另一个数据库更新,或将数据发送到另一个服务器。 这样的情况下,学习node.js是一个很好
I am designing a regular expression tester in HTML and JavaScript. The user will enter a regex, a string, and choose the function they want to test with (eg search, match, replace, etc.) via radio button and the program will display the results when that function is run with the specified arguments. Naturally there will be extra text boxes for the extra arguments to replace and such. My probl
我正在用HTML和JavaScript设计一个正则表达式测试器。 用户将输入一个正则表达式,一个字符串,并通过单选按钮选择他们想要测试的函数(例如搜索,匹配,替换等),当该函数以指定的参数运行时,程序将显示结果。 自然会有额外的文本框来替代额外的参数等。 我的问题是从用户获取字符串并将其转换为正则表达式。 如果我说,他们并不需要有//的周围,他们进入正则表达式,那么他们不能设置标志,如g和i 。 所以他们必须在表
I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with a jQuery selector. I have looked for this myself but have been unable to find information on the syntax and how to use it. Does anyone know where the documentation for the syntax is? EDIT: The attribute filters allow you to select based on patterns of an attribute value. James Padolse
我正在使用通配符或正则表达式(不确定使用确切的术语)使用jQuery选择器的文档。 我一直在寻找这个,但一直无法找到有关语法和如何使用它的信息。 有谁知道语法的文档在哪里? 编辑:属性过滤器允许您根据属性值的模式进行选择。 James Padolsey创建了一个美妙的过滤器,允许正则表达式用于选择。 假设你有以下div : <div class="asdf"> Padolsey's :regex过滤器可以像这样选择它: $("div:regex(class,
I just came across the following function below: function hexToRgb(hex){ // By Tim Down - http://stackoverflow.com/a/5624139/3493650 // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-fd])([a-fd])([a-fd])$/i; hex = hex.replace(shorthandRegex, function(m, r, g, b) { return r + r + g + g + b + b; }); Now I tried the following regex in my
我刚刚遇到下面的函数: function hexToRgb(hex){ // By Tim Down - http://stackoverflow.com/a/5624139/3493650 // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-fd])([a-fd])([a-fd])$/i; hex = hex.replace(shorthandRegex, function(m, r, g, b) { return r + r + g + g + b + b; }); 现在我在浏览器控制台中尝试了以下正则表达式: s = "#ddd" s.matc
I want to count characters, but they may be separated by characters that do not match. Here is an example. I want to match a text that has 10 or more word-characters. It may include spaces but i don't want to count the spaces. Should not match: "foo bar baz" (should count 9) Should not match: "a a" (should count 2) Should match: "foo baz bars"
我想计算字符数,但它们可能会被不匹配的字符分隔。 这是一个例子。 我想匹配一个包含10个或更多单词字符的文本。 它可能包含空格,但我不想计算空格。 不应该匹配:“foo bar baz”(应计数9) 不应该匹配:“a a”(应计为2) 应该匹配:“foo baz吧”(应该算10,匹配整个字符串) 这就是我想出来的,但它包括了整个事情: ((?<=s)*w(?=s)*){10} 编辑我不想包含计数空间。 对不起,我编辑了几次,我没有正确描述
Possible Duplicate: Escape string for use in Javascript regex I have a msg like this: Max {0} chars allowed in {1} And I have a function to create a message using the arguments passed as for(var i = 0; i < agrs.length; i++){ reg = new RegExp('{'+i+'}', 'gi'); key = key.replace(reg,agrs[i]) } The problem is that it's not able to take the param i to create the reg exp. Wh
可能重复: 转义字符串在Javascript正则表达式中使用 我有这样的味精: {1}允许的最大{0}个字符 我有一个函数可以使用传递的参数来创建消息 for(var i = 0; i < agrs.length; i++){ reg = new RegExp('{'+i+'}', 'gi'); key = key.replace(reg,agrs[i]) } 问题是,它不能够采取帕拉姆i创造了reg进出口。 有什么办法实现这一点? 您的正则表达式是/{0}/gi因为您是通过字符串创建的。 这不是一个有效的
I came across a strange behaviour when doing some regular expressions in JavaScript today (Firefox 3 on Windows Vista). var str = "format_%A"; var format = /(?:^|s)format_(.*?)(?:s|$)/.exec(str); console.log(format); // ["format_%A", "%A"] console.log(format[0]); // "format_undefined" console.log(format[1]); // Undefined There's nothing wrong with the regular expression. As you can see
我今天在JavaScript中使用一些正则表达式时遇到了奇怪的行为(Windows Vista上的Firefox 3)。 var str = "format_%A"; var format = /(?:^|s)format_(.*?)(?:s|$)/.exec(str); console.log(format); // ["format_%A", "%A"] console.log(format[0]); // "format_undefined" console.log(format[1]); // Undefined 正则表达式没有任何问题。 正如你所看到的,它已经匹配了第一个console.log调用中的正确部分。 Internet
I know, I know there must be some threads covering this topic. But I used the search and didn't get the answer which fits my needs. So here we go: How do I check a variable if it's null or undefined and what is the difference between the null and undefined ? What is the difference between "==" and "===" (it's hard to search Google for === )? How do I check
我知道,我知道必须有一些涵盖这个主题的主题。 但我使用了搜索功能,没有得到符合我需求的答案。 所以我们走吧: 如何检查变量是否为null或undefined以及null和undefined之间的区别是什么? “==”和“===”有什么区别(很难搜索谷歌=== )? 如何检查变量是否为null或undefined ... 变量为null : if (a === null) // or if (a == null) // but see note below ......但请注意,如果a undefined ,后者也将是真实的。