Category Archives: javascript

Pluralsight Continuous Play User Scripts

By default, it will stop after each module when you studying on Pluralsight. If you want to save the mouse click to automatically view the next module. You can use the following methods. Install Greasemonkey addon for firefox: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/ Install my user scripts: http://userscripts.org/scripts/show/485571 Now when you reach each end of module, the next module… Read More »

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 »

ASTreeView 1.1.1 Released

The new version of ASTreeView includes: Some bugs fixed: In DropdownTreeView, the RequiredValidator cannot be disabled. Javascript error when ajax request failed. Tree line does not display correctly after move the last node. Initialization of the treeview may cause js error if in the low bandwidth. New features: Add Sever-Side ExpandAll, CollapseAll, ExpandTo(depth) Methods. Add… Read More »

ASTreeView: Resolve confliction with jQuery

Thanks xiaot for reporting this issue that if jQuery is included in page, it conflicts with the ASTreeView. To resolve this issue, we can use the noconflict method of the jQuery: <script src=”jquery-1.3.2.js”></script> <script type=”text/javascript”> var J = jQuery.noConflict(); </script> Now $("#foo") will be J("#foo") and it will not conflict with the ASTreeView. I’ll update… Read More »

正确设置绝对定位的dom元素的位置

先前在做ASTreeView右键菜单时遇到一个问题,是这样的: 因为页面的布局中,放置ASTreeView控件的容器叫container,当用户右键点击树节点时,edit, delete节点的菜单出现。由于container的position是relative的,右键菜单的div的position是absolute的,所以,设置菜单div的left, top属性时,会根据container的位置去定位,如图所示:   当用户点击右键,我们可以获取当前鼠标的坐标,这时,如果直接将鼠标的x,y坐标赋值给菜单的left和top就会出问题。因为鼠标坐标的原点是窗口的左上角,而菜单的原点是container的左上角。 那如何让菜单显示在鼠标点击的位置呢?接下来的代码将一步一步地实现: 首先是获取鼠标坐标的代码: function getMousePos(e) { e = e || event; var posx = 0; var posy = 0; if ( e.pageX && e.pageY ) { posx = e.pageX; posy = e.pageY; } else if (e.clientX && e.clientY ) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY… Read More »

用脚本修复IE6 select overlap bug(遮盖问题)

IE6有个bug,不论如何设div的z-index, IE6的select总会显示在最前,我们都无法使用DIV遮挡住select元素。 今天写了个类,解决了这个问题,先贴上代码,然后写如何使用: namespace: if (typeof(rdcjs) == "undefined") _rdc = rdcjs = {};   IE6SelectHelper class: _rdc.IE6SelectHelper = function(){ this.selectList = new Array(); } _rdc.IE6SelectHelper.prototype = { isInRange : function( elem, containerId ){ //alert(this.idAs); var containerDiv = document.getElementById( containerId ); if( !containerDiv ) return false; //as_asName_txtSuggestBoxasName var elemX1 = this.getX( elem ); var elemY1 =… Read More »

一个简单的javascript字符计数器

公司一个项目里有发短信功能,要在页面上提示用户还剩多少字符可以输入,当用户输入的字符数超过最大字符限制,则截取最大字符数的数目。代码还是比较简单的,也算是记录一下。 代码如下: HTML部分: <textarea id=”txtContainer” rows=”3″ cols=”40″ ></textarea> <br /> words left: <input id=”txtWordCount” type=”text” readonly=”true” style=”width:40px;” /> javascript部分: <script type=”text/javascript”> function containerKeyupHandler( e ){ var count = “10”; var evt = e || window.event; var elm = evt.target || evt.srcElement; var tex = elm.value; var len = tex.length; var wordCount = document.getElementById(“txtWordCount”); wordCount.value =… 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 »