文章标签 ‘javascript’

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/copy_to_clipboard/ 从 discuz! 里扒出来的(简易实现), 代码如下: var clipboardswfdata; var setcopy_gettext = function(){ clipboardswfdata = document.getElementById('data').value; window.document.clipboardswf.SetVariable('str', clipboardswfdata); } var floatwin = function(){ alert('copy success, ' + clipboardswfdata); } <input type="text" name="data" value="xxxxx11111" id ="data" /> <div id="clipboard_content"> <span class="clipinner" id="clipinner">点此复制到剪贴板 <embed name="clipboardswf" class="clipboardswf" id="clipboardswf" onmouseover="setcopy_gettext()" devicefont="false" src="./clipboard.swf" menu="false" allowscriptaccess="sameDomain" swliveconnect="true" wmode="transparent" type="application/x-shockwave-flash" height="20" width="100"></span> [...]

2010年4月13日14:48 | 2 条评论

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/ajax_char_lose/ 采用Ajax传递数据时,通常会将数据整理为data="var1=abc&var2=def"。而当数据中存在加号(+)或是连接符(&)时,服务器端接收数据时会有部分数据丢失现象。分析一下Ajax传递数据的格式与Javascript的语法不难发现: 1. "+"号:JavaScript解析为字符串连接符,所以服务器端接收数据时"+"会丢失。 2. "&":JavaScript解析为变量连接符,所以服务器端接收数据时&符号以后的数据都会丢失。 解决办法也相当简单,只需要为+与&符号编码即可: function vchar(str) { str = str.replace(/\+/g, "%2B"); str = str.replace(/\&/g, "%26"); return str; } var1 = "abc+kef"; var2 = "abc&kef"; var1 = vchar(var1); var2 = vchar(var2); alert(var1); alert(var2); 使用jquery的话可以使用如下方式提交 var params = $('input, textarea').serialize(); $.ajax({ type: 'post', url: 'xxxx.php', data: params, success: function(response){ ...... } }); [...]

2009年1月8日11:09 | 没有评论

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/limit_textarea_length_by_js/ From: http://www.phpcake.cn/archives/26/ <script type="text/javascript"> function ismaxlength(obj){ var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "" if (obj.getAttribute && obj.value.length>mlength) obj.value=obj.value.substring(0,mlength) } </script> <textarea maxlength="10" onkeyup="return ismaxlength(this)"></textarea> -- EOF --

2008年1月23日14:20 | 没有评论
分类: WebDesign
标签:

转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/auto_resize_images/ resizeimg.js window.onload = function() { for (var index = 0; index < document.images.length; index++) { var widthRestriction = 400; var heightRestriction = 400; var rate = document.images[index].width / document.images[index].height; if (document.images[index].width > widthRestriction) { document.images[index].width = widthRestriction; document.images[index].height = widthRestriction / rate; } else if (document.images[index].height > heightRestriction) { document.images[index].height = heightRestriction; [...]

2008年1月12日15:34 | 没有评论
分类: WebDesign