本页是js命名空间首页。与js、ajax等有关的内容放此命名空间下。

导航

JS小技巧

  1. 复制内容到剪切板
function setCopy(_sTxt){try{clipboardData.setData('Text',_sTxt); alert("网址粘贴成功!");}catch(e){}}
function copyToClipboard(txt) {    
          if(window.clipboardData) {     
                  window.clipboardData.clearData();     
                  window.clipboardData.setData("Text", txt);     
          } else if(navigator.userAgent.indexOf("Opera") != -1) {     
               window.location = txt;     
          } else if (window.netscape) {     
               try {     
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");     
               } catch (e) {     
                    alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");     
               }     
               var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);     
               if (!clip)     
                    return;     
               var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);     
               if (!trans)     
                    return;     
               trans.addDataFlavor('text/unicode');     
               var str = new Object();     
               var len = new Object();     
               var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);     
               var copytext = txt;     
               str.data = copytext;     
               trans.setTransferData("text/unicode",str,copytext.length*2);     
               var clipid = Components.interfaces.nsIClipboard;     
               if (!clip)     
                    return false;     
               clip.setData(trans,null,clipid.kGlobalClipboard);     
               alert("复制成功!")     
          }     
    }  
  1. 数组定义: var a = [a,b] ;
  1. 加入收藏
     <a href="javascript:window.external.AddFavorite('http://www.soften.cn/','红麦软件')">添加收藏</a>
    
  1. 设为首页
     <a href="###" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.soften.cn/');">设为首页</a>
    

JS兼容问题

  1. 得到某个对象的绝对坐标
function GetPoint(source)
{
  var tmp = source;
  var pt = new Object();
  if(source.getBoundingClientRect)
  {
     var rc = source.getBoundingClientRect();
     pt.x = rc.left - 2;
     pt.y = rc.top - 2;    
  }
  else
  {
    pt.x = 0;
    pt.y = 0;
    do
    {
      pt.x += tmp.offsetLeft;
      pt.y += tmp.offsetTop;
      tmp = tmp.offsetParent;
    }
    while(tmp != null && tmp.tagName!="BODY");
  }
  return pt;
}

资料

  1. 非常多的js效果,拖拽等 http://www.dhtmlgoodies.com/index.html
  2. 无忧脚本 http://bbs.51js.com/
  3. lightbox2 http://www.huddletogether.com/projects/lightbox2/ 这个不错,包括图片、组图、div、iframe、ajax几种方式的处理
  4. thickbox http://jquery.com/demo/thickbox/ ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library. Its function is to show a single image, multiple images, inline content, iframed content, or content served through AJAX in a hybrid modal.
js/start.txt · 最后更改: 2011/04/11 15:13 由 alex_best
到顶部
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0 红麦软件 红麦软件