上传图片附件显示缩略图

刚开始以为很容易解决.写js嘛..-_,-+


< i nput type="file" onchange="document.getElementById('showimg').src=this.value;" />

然而本地测试成功的代码上传到服务器上就出现了错误..空格被自动转义成为了%20

无语ing….囧..

不过总算找到一个BT的方法..用CSS中的AlphaImageLoader滤镜 -_!!

AlphaImageLoader滤镜的使用方法就不做说明..自己查下手册

AlphaImageLoader滤镜的src属就是其中的主角 它将使用绝对或相对url地址指定背景图像。假如忽略此参数,滤镜将不会作用。

放出代码

全文阅读 »

JS常用代码:五行搞定checkbox全选/全不选

经常会用到的JS代码.记录一下.以后用得着

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>无标题文档</title>
  6. <style type="text/css">
  7. p {margin:0;font-size:12px;line-height:26px;}
  8. </style>
  9. <script type="text/javascript">
  10. function check_all(obj,cName)
  11. {
  12.     var checkboxs = document.getElementsByName(cName);
  13.     for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
  14. }
  15. </script>
  16. </head>
  17.  
  18. <body>
  19. <p><input type="checkbox" name="all" onclick="check_all(this,'c')" />全选/全不选</p>
  20. <p><input type="checkbox" name="c" value="" /></p>
  21. <p><input type="checkbox" name="c" value="" /></p>
  22. <p><input type="checkbox" name="c" value="" /></p>
  23. <p><input type="checkbox" name="c" value="" /></p>
  24. </body>
  25. </html>

仿WINODWS警告提示Firefox广告

不知道效果如何,先挂在自己的表情站上试试,毕竟google广告里最有价值的还是Firefox的广告推荐了

实现代码如下:

先在 < body > 后加上这么一段

  1. <div id="firefox">
  2. <a href="/firefox/" target="_new">还在用过时的IE浏览器?远离网络病毒,木马,恶意软件的入侵攻击,强烈建议下载安装【最快.最安全】的浏览器:火狐Firefox2.0</a>
  3. <img src="close.gif" id="foxclose" />
  4. </div>
  5. <script type="text/javascript" src="firefox.js"></script>

CSS部分:

  1. #firefox {
  2.     height:25px;
  3.     width:100%;
  4.     background:url(warning.gif) no-repeat 8px 3px #ffb;
  5.     border-bottom:1px solid #ffdb4d;
  6.     line-height:25px;
  7.     display:none;
  8. }
  9.  
  10. #firefox a {
  11.     color:#52271d;
  12.     float:left;
  13.     margin-left:170px;
  14. }
  15.  
  16. #firefox img {
  17.     dispaly:block;
  18.     float:right;
  19.     margin:7px 6px 0 0;
  20.     cursor:pointer;
  21. }

全文阅读 »

JS存档:insertAfter()函数

insertAfter(newElement, targetElement)
newElement 创建的新元素
targetElement 插入到这个元素之后

JS没有内置这个函数真是不方便呐.存档方便今后查找

  1. function insertAfter(newElement, targetElement)
  2. {
  3.     var parent = targetElement.parentNode;
  4.     if(parent.lastChild == targetElement) 
  5.     {
  6.         parent.appendChild(newElement);
  7.     } 
  8.     else
  9.     {
  10.         parent.insertBefore(newElement, targetElement.nextSibling);
  11.     }
  12. }

JS中文字符串转换unicode编码函数

AJAX传递中文字符串时必须把中文字符串编码成unicode,一般会用到JS的自带函数escape().不过找到了更好的函数来确决中文字符转换成unicode编码的函数

  1. function uniencode(text)
  2. {
  3.     text = escape(text.toString()).replace(/\+/g, "%2B");
  4.     var matches = text.match(/(%([0-9A-F]{2}))/gi);
  5.     if (matches)
  6.     {
  7.         for (var matchid = 0; matchid < matches.length; matchid++)
  8.         {
  9.             var code = matches[matchid].substring(1,3);
  10.             if (parseInt(code, 16) >= 128)
  11.             {
  12.                 text = text.replace(matches[matchid], '%u00' + code);
  13.             }
  14.         }
  15.     }
  16.     text = text.replace('%25', '%u0025');
  17.  
  18.     return text;
  19. }

当然服务器端要对编码过的字符串进行第二次转码.把字符串转换成UTF-8编码.

全文阅读 »

浏览最多的10篇日志

评论最多的10篇日志

随机显示的10篇日志