Tag Archives: javascript

JavaScript File Selection Simulation

Context The build-in file selection elements of browsers are ugly and cannot be customized easily. If developer need to change the appearance of the file selection element, it’s almost impossible because of some security issues. So I wrote this script to simulate the file input selection by javascript so that the end user can click… Read More »

javascript closure(闭包)的一个示例

今天一个同事看到John Resig 的Pro JavaScript Techniques这本书上的37页上有一段关于闭包的javascript代码,怎么调试都运行不正确,于是和他一起研究了一下,代码是这样的:   // Create a new user object that accepts an object of properties function User( properties ) { // Iterate through the properties of the object, and make sure // that it’s properly scoped (as discussed previously) for ( var i in properties ) { (function(){ //using this here is… Read More »

javascript在货币中加逗号

在做一个智利的项目的时候,有个算buget的页面,需要显示货币时数字之间每3位用逗号分隔,而且计算都是在客户端进行,所以就用javascript实现。 代码如下,包含了加逗号和移除逗号 function addCommas(nStr) { nStr += ”; x = nStr.split(‘.’); x1 = x[0]; x2 = x.length > 1 ? ‘.’ + x[1] : ”; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, ‘$1’ + ‘,’ + ‘$2’); } return x1 + x2; } function remCommas(nStr) { return nStr.replace(/\./g , ”).replace(‘%’,”).replace(‘ ‘,”).replace(‘,’,’.’); }

ASP.Net按钮提交前执行javascript

here is the code… 在提交前执行一段js <script language=“javascript“> function doSomething() { // 执行自己的javascript // 继续提交 this.click();} </script> <asp:button onmousedown=“doSomething()“ id=“someButton” Text=”提交” runat=”server”> </asp:button>