﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>学习日记 &#187; JavaScript</title>
	<atom:link href="https://www.softwareace.cn/?cat=100&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.softwareace.cn</link>
	<description>时刻想着为自己的产品多做一些对他好的事情</description>
	<lastBuildDate>Fri, 20 Mar 2026 06:58:28 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>Can (a ==1 &amp;&amp; a== 2 &amp;&amp; a==3) ever evaluate to true?</title>
		<link>https://www.softwareace.cn/?p=1722</link>
		<comments>https://www.softwareace.cn/?p=1722#comments</comments>
		<pubDate>Thu, 25 Jan 2018 09:14:27 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1722</guid>
		<description><![CDATA[https://stackoverflow.com/questions/48270127/can-a-1-a- [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever-evaluate-to-true</p>
<p></p><pre class="crayon-plain-tag">const a = {
  i: 1,
  toString: function () {
    return a.i++;
  }
}

if(a == 1 &amp;&amp; a == 2 &amp;&amp; a == 3) {
  console.log('Hello World!');
}</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1722</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>动态加载js和css</title>
		<link>https://www.softwareace.cn/?p=1641</link>
		<comments>https://www.softwareace.cn/?p=1641#comments</comments>
		<pubDate>Wed, 10 May 2017 02:17:48 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1641</guid>
		<description><![CDATA[开发过程中经常需要动态加载js和css，今天特意总结了一下常用的方法。  1、动态加载js 　　方法一：动态加 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="color: #393939;">开发过程中经常需要动态加载js和css，今天特意总结了一下常用的方法。</p>
<h4> 1、动态加载js</h4>
<p style="color: #393939;">　　方法一：动态加载js文件</p>
<p></p><pre class="crayon-plain-tag">// 动态加载js脚本文件
function loadScript(url) {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = url;
  document.body.appendChild(script);
}
// 测试
loadScript("javascript/lib/cookie.js");</pre><p><span style="color: #393939;">方法二：动态加载js脚本</span></p><pre class="crayon-plain-tag">// 动态加载js脚本
    function loadScriptString(code) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        try{
            // firefox、safari、chrome和Opera
            script.appendChild(document.createTextNode(code));
        }catch(ex) {
            // IE早期的浏览器 ,需要使用script的text属性来指定javascript代码。
            script.text = code;
        }
        document.body.appendChild(script);
    }
    // 测试
    var text = "function test(){alert('test');}";
    loadScriptString(text);
    test();</pre><p>&nbsp;</p>
<h4>2、动态加载css</h4>
<p style="color: #393939;">　　方法一：动态加载css文件</p>
<p></p><pre class="crayon-plain-tag">// 动态加载css文件
    function loadStyles(url) {
        var link = document.createElement("link");
        link.type = "text/css";
        link.rel = "stylesheet";
        link.href = url;
        document.getElementsByTagName("head")[0].appendChild(link);
    }
    // 测试
    loadStyles("css/secondindex.css");</pre><p><span style="color: #393939;">方法二：动态加载css脚本</span></p><pre class="crayon-plain-tag">// 动态加载css脚本
    function loadStyleString(cssText) {
        var style = document.createElement("style");
        style.type = "text/css";
        try{
            // firefox、safari、chrome和Opera
            style.appendChild(document.createTextNode(cssText));
        }catch(ex) {
            // IE早期的浏览器 ,需要使用style元素的stylesheet属性的cssText属性
            style.styleSheet.cssText = cssText;
        }
        document.getElementsByTagName("head")[0].appendChild(style);
    }
    // 测试
    var css = "body{color:blue;}";
    loadStyleString(css);</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1641</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>获取浏览器语言的完美方案</title>
		<link>https://www.softwareace.cn/?p=1638</link>
		<comments>https://www.softwareace.cn/?p=1638#comments</comments>
		<pubDate>Tue, 02 May 2017 01:58:24 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1638</guid>
		<description><![CDATA[http://www.w3help.org/zh-cn/causes/BX2040 &#160; 标准参考 &#038; [&#8230;]]]></description>
				<content:encoded><![CDATA[<div id="article_content" class="article_content" style="color: #000000;">
<p><a style="color: #ca0000;" href="http://www.w3help.org/zh-cn/causes/BX2040" target="_blank">http://www.w3help.org/zh-cn/causes/BX2040</a></p>
<p>&nbsp;</p>
<h2 id="standard_reference"><a style="color: #ca0000;" name="t0"></a>标准参考</h2>
<p>&nbsp;</p>
<p>无</p>
<h2 id="description"><a style="color: #ca0000;" name="t1"></a>问题描述</h2>
<p>各浏览器对 navigator 对象中几个与语言相关的属性（language、userLanguage、browserLanguage、 systemLanguage）的返回值存在很大的差异。</p>
<h2 id="influence"><a style="color: #ca0000;" name="t2"></a>造成的影响</h2>
<p>由于不同浏览器对这几个属性的返回值有很大差异，同时返回的有效值的大小写也有差异。若在获取当前浏览器语言的时候没有考虑到这些差异则可能造成兼容性问题。</p>
<h2 id="impacted_browsers"><a style="color: #ca0000;" name="t3"></a>受影响的浏览器</h2>
<table class="list  ">
<tbody>
<tr>
<th>所有浏览器</th>
<td></td>
</tr>
</tbody>
</table>
<h2 id="analysis_of_issues"><a style="color: #ca0000;" name="t4"></a>问题分析</h2>
<p>首先查看一下 navigator 对象中的这几个与 language 相关的属性。</p>
<p>navigator 对象包含有关浏览器的信息。没有应用于 navigator 对象的公开标准，不过所有浏览器都支持该对象。但是其内部一些属性及其返回值在各浏览器并不统一。</p>
<ul>
<li>language：返回当前的浏览器语言（来自 Mozilla Developer Center）</li>
<li>userLanguage：返回操作系统设定的自然语言（来自 MSDN）</li>
<li>browserLanguage：返回当前的浏览器语言（来自 MSDN）</li>
<li>systemLanguage：返回当前操作系统的缺省语言（来自 MSDN）</li>
</ul>
<p>关于 navigator 对象的更多资料，请参见：MSDN、Mozilla Developer Center。</p>
<p>对于浏览器，Mozilla Developer Center 中的 language 属性与 MSDN 中的 browserLanguage 属性描述很像。</p>
<p>分析以下代码：</p><pre class="crayon-plain-tag">&amp;lt;script&amp;gt;
document.write('navigator.language:'+navigator.language);
document.write('&amp;lt;br&amp;gt;navigator.userLanguage:'+navigator.userLanguage);
document.write('&amp;lt;br&amp;gt;navigator.browserLanguage:'+navigator.browserLanguage);
document.write('&amp;lt;br&amp;gt;navigator.systemLanguage:'+navigator.systemLanguage);
&amp;lt;/script&amp;gt;</pre><p>代码中打印出了各浏览器对于这 4 个属性返回值的情况：</p>
<table class="compare  ">
<tbody>
<tr>
<th></th>
<th>IE6 IE7 IE8</th>
<th>Firefox Chrome Safari</th>
<th>Opera</th>
</tr>
<tr>
<th>navigator.language</th>
<td>undefined</td>
<td>zh-CN</td>
<td>zh-CN</td>
</tr>
<tr>
<th>navigator.userLanguage</th>
<td>zh-cn</td>
<td>undefined</td>
<td>zh-cn</td>
</tr>
<tr>
<th>navigator.browserLanguage</th>
<td>zh-cn</td>
<td>undefined</td>
<td>zh-cn</td>
</tr>
<tr>
<th>navigator.systemLanguage</th>
<td>zh-cn</td>
<td>undefined</td>
<td>undefined</td>
</tr>
</tbody>
</table>
<h2 id="solutions"><a style="color: #ca0000;" name="t5"></a>解决方案</h2>
<p>可以使用下面的代码获取当前浏览器语言：</p><pre class="crayon-plain-tag">&lt;span style=&quot;color: #ff0000;&quot;&gt;&lt;strong&gt;(navigator.language || navigator.browserLanguage).toLowerCase()&lt;/strong&gt;&lt;/span&gt;</pre><p>&nbsp;</p>
<p>示例：&lt;以下示例由博主吕津增加&gt;</p>
<p><img src="http://img.blog.csdn.net/20140710200501187?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHZqaW4xMTA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" /></p>
<p>&nbsp;</p>
<p>PS:</p>
<p>如下图所示，navigator.browserLanguage、navigator.systemLanguage、navigator.userLanguage这三个属性对FireFox不支持。</p>
<p><a style="color: #ca0000;" href="http://www.w3school.com.cn/tiy/t.asp?f=hdom_navigator" target="_blank">http://www.w3school.com.cn/tiy/t.asp?f=hdom_navigator</a></p>
<p><img src="http://img.blog.csdn.net/20140710201232666?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHZqaW4xMTA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" /></p>
<p><img src="http://img.blog.csdn.net/20140710201259811?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHZqaW4xMTA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" /></p>
<p>&nbsp;</p>
</div>
<div class="bdsharebuttonbox tracking-ad bdshare-button-style0-16" style="color: #000000;" data-mod="popu_172" data-bd-bind="1493690166055"></div>
<div id="digg" style="color: #000000;"></div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1638</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery获取浏览器窗口的可视区域高度和宽度,滚动条高度</title>
		<link>https://www.softwareace.cn/?p=1635</link>
		<comments>https://www.softwareace.cn/?p=1635#comments</comments>
		<pubDate>Mon, 24 Apr 2017 09:31:52 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1635</guid>
		<description><![CDATA[[crayon-69f1ed8075deb453852682/] &#160;]]></description>
				<content:encoded><![CDATA[<div class="line number1 index0 alt2" style="color: #000000;">
<pre class="crayon-plain-tag">alert($(window).height()); //浏览器时下窗口可视区域高度
alert($(document).height()); //浏览器时下窗口文档的高度
alert($(document.body).height());//浏览器时下窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin
alert($(window).width()); //浏览器时下窗口可视区域宽度
alert($(document).width());//浏览器时下窗口文档对于象宽度
alert($(document.body).width());//浏览器时下窗口文档body的高度
alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin
  
alert($(document).scrollTop()); //获取滚动条到顶部的垂直高度
alert($(document).scrollLeft()); //获取滚动条到左边的垂直宽度</pre><br />
&nbsp;</p>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1635</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript canvas show circle picture</title>
		<link>https://www.softwareace.cn/?p=1310</link>
		<comments>https://www.softwareace.cn/?p=1310#comments</comments>
		<pubDate>Mon, 04 May 2015 02:18:51 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1310</guid>
		<description><![CDATA[[crayon-69f1ed8075fce269806725/] &#160;]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"/&gt;
    &lt;title&gt;Canvas tutorial&lt;/title&gt;
    &lt;script type="text/javascript"&gt;
      function draw(){
        var canvas = document.getElementById('tutorial');
        if (canvas.getContext){
          var ctx = canvas.getContext('2d');

          var thumbImg = document.createElement('img');

          thumbImg.src = 'http://s1.sinaimg.cn/orignal/6e0be9fbh94318b5f9120&amp;690';
          thumbImg.onload = function() {
              ctx.save();
              ctx.beginPath();
              ctx.arc(50, 50, 50, 0, Math.PI * 2, true);
              ctx.closePath();
              ctx.clip();

              ctx.drawImage(thumbImg, 0, 0, 100, 100);

              ctx.beginPath();
              ctx.arc(0, 0, 50, 0, Math.PI * 2, true);
              ctx.clip();
              ctx.closePath();
              ctx.restore();
          };

        }
      }


    &lt;/script&gt;
    &lt;style type="text/css"&gt;
      canvas { border: 1px solid black; }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body onload="draw();"&gt;
    &lt;canvas id="tutorial" width="150" height="150"&gt;&lt;/canvas&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1310</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript生成UUID的两种方式</title>
		<link>https://www.softwareace.cn/?p=1198</link>
		<comments>https://www.softwareace.cn/?p=1198#comments</comments>
		<pubDate>Wed, 11 Feb 2015 05:27:20 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1198</guid>
		<description><![CDATA[[crayon-69f1ed8076217578895181/] &#160; [crayon-69f1ed8 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">/*!
Math.uuid.js (v1.4)
http://www.broofa.com
mailto:robert@broofa.com
 
Copyright (c) 2010 Robert Kieffer
Dual licensed under the MIT and GPL licenses.
*/
 
/*
 * Generate a random uuid.
 *
 * USAGE: Math.uuid(length, radix)
 *   length - the desired number of characters
 *   radix  - the number of allowable values for each character.
 *
 * EXAMPLES:
 *   // No arguments  - returns RFC4122, version 4 ID
 *   &gt;&gt;&gt; Math.uuid()
 *   "92329D39-6F5C-4520-ABFC-AAB64544E172"
 *
 *   // One argument - returns ID of the specified length
 *   &gt;&gt;&gt; Math.uuid(15)     // 15 character ID (default base=62)
 *   "VcydxgltxrVZSTV"
 *
 *   // Two arguments - returns ID of the specified length, and radix. (Radix must be &lt;= 62)
 *   &gt;&gt;&gt; Math.uuid(8, 2)  // 8 character ID (base=2)
 *   "01001010"
 *   &gt;&gt;&gt; Math.uuid(8, 10) // 8 character ID (base=10)
 *   "47473046"
 *   &gt;&gt;&gt; Math.uuid(8, 16) // 8 character ID (base=16)
 *   "098F4D35"
 */
(function() {
  // Private array of chars to use
  var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
 
  Math.uuid = function (len, radix) {
    var chars = CHARS, uuid = [], i;
    radix = radix || chars.length;
 
    if (len) {
      // Compact form
      for (i = 0; i &lt; len; i++) uuid[i] = chars[0 | Math.random()*radix];
    } else {
      // rfc4122, version 4 form
      var r;
 
      // rfc4122 requires these characters
      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
      uuid[14] = '4';
 
      // Fill in random data.  At i==19 set the high bits of clock sequence as
      // per rfc4122, sec. 4.1.5
      for (i = 0; i &lt; 36; i++) {
        if (!uuid[i]) {
          r = 0 | Math.random()*16;
          uuid[i] = chars[(i == 19) ? (r &amp; 0x3) | 0x8 : r];
        }
      }
    }
 
    return uuid.join('');
  };
 
  // A more performant, but slightly bulkier, RFC4122v4 solution.  We boost performance
  // by minimizing calls to random()
  Math.uuidFast = function() {
    var chars = CHARS, uuid = new Array(36), rnd=0, r;
    for (var i = 0; i &lt; 36; i++) {
      if (i==8 || i==13 ||  i==18 || i==23) {
        uuid[i] = '-';
      } else if (i==14) {
        uuid[i] = '4';
      } else {
        if (rnd &lt;= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
        r = rnd &amp; 0xf;
        rnd = rnd &gt;&gt; 4;
        uuid[i] = chars[(i == 19) ? (r &amp; 0x3) | 0x8 : r];
      }
    }
    return uuid.join('');
  };
 
  // A more compact, but less performant, RFC4122v4 solution:
  Math.uuidCompact = function() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&amp;0x3|0x8);
      return v.toString(16);
    });
  };
})();</pre><p>&nbsp;</p><pre class="crayon-plain-tag">/*

uuid.js - Version 0.2
JavaScript Class to create a UUID like identifier

Copyright (C) 2006-2008, Erik Giberti (AF-Design), All rights reserved.

This program is free software; you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by the Free Software 
Foundation; either version 2 of the License, or (at your option) any later 
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY 
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
Place, Suite 330, Boston, MA 02111-1307 USA

The latest version of this file can be downloaded from
http://www.af-design.com/resources/javascript_uuid.php

HISTORY:
6/5/06 	- Initial Release
5/22/08 - Updated code to run faster, removed randrange(min,max) in favor of
          a simpler rand(max) function. Reduced overhead by using getTime() 
          method of date class (suggestion by James Hall).

KNOWN ISSUES:
- Still no way to get MAC address in JavaScript
- Research into other versions of UUID show promising possibilities 
  (more research needed)
- Documentation needs improvement

*/

// On creation of a UUID object, set it's initial value
function UUID(){
	this.id = this.createUUID();
}

// When asked what this Object is, lie and return it's value
UUID.prototype.valueOf = function(){ return this.id; }
UUID.prototype.toString = function(){ return this.id; }

//
// INSTANCE SPECIFIC METHODS
//

UUID.prototype.createUUID = function(){
	//
	// Loose interpretation of the specification DCE 1.1: Remote Procedure Call
	// described at http://www.opengroup.org/onlinepubs/009629399/apdxa.htm#tagtcjh_37
	// since JavaScript doesn't allow access to internal systems, the last 48 bits 
	// of the node section is made up using a series of random numbers (6 octets long).
	//  
	var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
	var dc = new Date();
	var t = dc.getTime() - dg.getTime();
	var h = '-';
	var tl = UUID.getIntegerBits(t,0,31);
	var tm = UUID.getIntegerBits(t,32,47);
	var thv = UUID.getIntegerBits(t,48,59) + '1'; // version 1, security version is 2
	var csar = UUID.getIntegerBits(UUID.rand(4095),0,7);
	var csl = UUID.getIntegerBits(UUID.rand(4095),0,7);

	// since detection of anything about the machine/browser is far to buggy, 
	// include some more random numbers here
	// if NIC or an IP can be obtained reliably, that should be put in
	// here instead.
	var n = UUID.getIntegerBits(UUID.rand(8191),0,7) + 
			UUID.getIntegerBits(UUID.rand(8191),8,15) + 
			UUID.getIntegerBits(UUID.rand(8191),0,7) + 
			UUID.getIntegerBits(UUID.rand(8191),8,15) + 
			UUID.getIntegerBits(UUID.rand(8191),0,15); // this last number is two octets long
	return tl + h + tm + h + thv + h + csar + csl + h + n; 
}


//
// GENERAL METHODS (Not instance specific)
//


// Pull out only certain bits from a very large integer, used to get the time
// code information for the first part of a UUID. Will return zero's if there 
// aren't enough bits to shift where it needs to.
UUID.getIntegerBits = function(val,start,end){
	var base16 = UUID.returnBase(val,16);
	var quadArray = new Array();
	var quadString = '';
	var i = 0;
	for(i=0;i&lt;base16.length;i++){
		quadArray.push(base16.substring(i,i+1));	
	}
	for(i=Math.floor(start/4);i&lt;=Math.floor(end/4);i++){
		if(!quadArray[i] || quadArray[i] == '') quadString += '0';
		else quadString += quadArray[i];
	}
	return quadString;
}

// Numeric Base Conversion algorithm from irt.org
// In base 16: 0=0, 5=5, 10=A, 15=F
UUID.returnBase = function(number, base){
	//
	// Copyright 1996-2006 irt.org, All Rights Reserved.	
	//
	// Downloaded from: http://www.irt.org/script/146.htm	
	// modified to work in this class by Erik Giberti
	var convert = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    if (number &lt; base) var output = convert[number];
    else {
        var MSD = '' + Math.floor(number / base);
        var LSD = number - MSD*base;
        if (MSD &gt;= base) var output = this.returnBase(MSD,base) + convert[LSD];
        else var output = convert[MSD] + convert[LSD];
    }
    return output;
}

// pick a random number within a range of numbers
// int b rand(int a); where 0 &lt;= b &lt;= a
UUID.rand = function(max){
	return Math.floor(Math.random() * max);
}

// end of UUID class file</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1198</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>use js set element style</title>
		<link>https://www.softwareace.cn/?p=1115</link>
		<comments>https://www.softwareace.cn/?p=1115#comments</comments>
		<pubDate>Tue, 20 Jan 2015 06:00:16 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1115</guid>
		<description><![CDATA[[crayon-69f1ed8076480337327004/] &#160;]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">var colorSpan = document.getElementById( 'btn-color-span');
colorSpan.style.backgroundColor = color;</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KindEditor/初始化参数</title>
		<link>https://www.softwareace.cn/?p=1109</link>
		<comments>https://www.softwareace.cn/?p=1109#comments</comments>
		<pubDate>Wed, 14 Jan 2015 03:49:09 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[kindeditor]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1109</guid>
		<description><![CDATA[KindEditor &#124; 使用方法 &#124; 初始化参数&#124;添加自定义插件&#124;API文档&#124;常见问题 width 编辑器的 [&#8230;]]]></description>
				<content:encoded><![CDATA[<table style="color: #000000;">
<tbody>
<tr>
<td><b><a style="color: #0b0080;" title="KindEditor" href="http://www.zzbaike.com/wiki/KindEditor">KindEditor</a></b> | <b><a style="color: #0b0080;" title="KindEditor/使用方法" href="http://www.zzbaike.com/wiki/KindEditor/%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95">使用方法</a></b> | <b>初始化参数</b>|<b><a style="color: #0b0080;" title="KindEditor/添加自定义插件" href="http://www.zzbaike.com/wiki/KindEditor/%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8F%92%E4%BB%B6">添加自定义插件</a></b>|<b><a style="color: #0b0080;" title="KindEditor/API文档" href="http://www.zzbaike.com/wiki/KindEditor/API%E6%96%87%E6%A1%A3">API文档</a></b>|<b><a style="color: #0b0080;" title="KindEditor/常见问题" href="http://www.zzbaike.com/wiki/KindEditor/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98">常见问题</a></b></td>
</tr>
</tbody>
</table>
<table style="color: #474747;">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<ul style="color: #474747;">
<li><b>width</b></li>
</ul>
<p style="color: #474747;"><a style="color: #0b0080;" title="编辑器" href="http://www.zzbaike.com/wiki/%E7%BC%96%E8%BE%91%E5%99%A8">编辑器</a>的宽度，可以设置px或%，比textarea输入框样式表宽度优先度高。</p>
<p style="color: #474747;">数据类型: String； 默认值: textarea输入框的宽度</p>
<p style="color: #474747;">示例:</p>
<p></p><pre class="crayon-plain-tag">K.create('#id', {
        width&nbsp;: '700px'
});</pre><p></p>
<ul style="color: #474747;">
<li><b>height</b></li>
</ul>
<p style="color: #474747;">编辑器的高度，只能设置px，比textarea输入框样式表高度优先度高。</p>
<p style="color: #474747;">数据类型: String； 默认值: textarea输入框的高度</p>
<ul style="color: #474747;">
<li><b>minWidth</b></li>
</ul>
<p style="color: #474747;">指定编辑器最小宽度，单位为px。</p>
<p style="color: #474747;">数据类型: Int； 默认值: 650</p>
<ul style="color: #474747;">
<li><b>items</b></li>
</ul>
<p style="color: #474747;">配置编辑器的工具栏，其中”/”表示换行，”|”表示分隔符。</p>
<p style="color: #474747;">数据类型: Array；</p>
<p style="color: #474747;">默认值:</p>
<p></p><pre class="crayon-plain-tag">[
        'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'cut', 'copy', 'paste',
        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
        'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'map', 'code', 'pagebreak',
        'link', 'unlink', '|', 'about'
]</pre><p></p>
<ul style="color: #474747;">
<li><b>noDisableItems</b></li>
</ul>
<p style="color: #474747;">designMode 为false时，要保留的工具栏图标。</p>
<p style="color: #474747;">数据类型: Array； 默认值: [‘source’, ‘fullscreen’]</p>
<ul style="color: #474747;">
<li><b>filterMode</b></li>
</ul>
<p style="color: #474747;">true时过滤<a style="color: #0b0080;" title="HTML" href="http://www.zzbaike.com/wiki/HTML">HTML</a><a class="mw-redirect" style="color: #0b0080;" title="代码" href="http://www.zzbaike.com/wiki/%E4%BB%A3%E7%A0%81">代码</a>，false时允许输入任何代码。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: false</p>
<ul style="color: #474747;">
<li><b>htmlTags</b></li>
</ul>
<p style="color: #474747;">指定要保留的HTML标记和属性。Object的key为HTML<a class="mw-redirect" style="color: #0b0080;" title="标签" href="http://www.zzbaike.com/wiki/%E6%A0%87%E7%AD%BE">标签</a>名，value为HTML属性数组，”.”开始的属性表示style属性。</p>
<p style="color: #474747;">数据类型: Object； 默认值:</p>
<p></p><pre class="crayon-plain-tag">{
        font&nbsp;: ['color', 'size', 'face', '.background-color'],
        span&nbsp;: [
                '.color', '.background-color', '.font-size', '.font-family', '.background',
                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
        ],
        div&nbsp;: [
                'align', '.border', '.margin', '.padding', '.text-align', '.color',
                '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
                '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
        ],
        table: [
                'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
                '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
                '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
                '.width', '.height'
        ],
        'td,th': [
                'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
                '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
                '.font-style', '.text-decoration', '.vertical-align', '.background'
        ],
        a&nbsp;: ['href', 'target', 'name'],
        embed&nbsp;: ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
        img&nbsp;: ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
        'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6'&nbsp;: [
                'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
        ],
        pre&nbsp;: ['class'],
        'hr,br,tbody,tr,strong,b,sub,sup,em,i,u,strike'&nbsp;: []
}</pre><p></p>
<ul style="color: #474747;">
<li><b>wellFormatMode</b></li>
</ul>
<p style="color: #474747;">true时美化HTML数据。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>resizeType</b></li>
</ul>
<p style="color: #474747;">2或1或0，2时可以拖动改变宽度和高度，1时只能改变高度，0时不能拖动。</p>
<p style="color: #474747;">数据类型: Int； 默认值: 2</p>
<ul style="color: #474747;">
<li><b>themeType</b></li>
</ul>
<p style="color: #474747;">指定主题风格，可设置”default”、”simple”，指定simple时需要引入simple.css。</p>
<p style="color: #474747;">数据类型: String； 默认值: “default”</p>
<p style="color: #474747;">示例:</p>
<p></p><pre class="crayon-plain-tag">&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../themes/default/default.css&quot; /&amp;gt;
&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../themes/simple/simple.css&quot; /&amp;gt;
&amp;lt;script charset=&quot;utf-8&quot; src=&quot;../kindeditor.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script charset=&quot;utf-8&quot; src=&quot;../lang/zh_CN.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
        var editor;
        KindEditor.ready(function(K) {
                editor = K.create('#editor_id', {
                        themeType&nbsp;: 'simple'
                });
        });
&amp;lt;/script&amp;gt;</pre><p></p>
<ul style="color: #474747;">
<li><b>langType</b></li>
</ul>
<p style="color: #474747;">指定语言，可设置”en”、”zh_CN”，需要引入lang/[langType].js。</p>
<p style="color: #474747;">数据类型: String； 默认值: “zh_CN”</p>
<p style="color: #474747;">示例:</p>
<p></p><pre class="crayon-plain-tag">&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;../themes/default/default.css&quot; /&amp;gt;
&amp;lt;script charset=&quot;utf-8&quot; src=&quot;../kindeditor.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script charset=&quot;utf-8&quot; src=&quot;../lang/en.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
        var editor;
        KindEditor.ready(function(K) {
                editor = K.create('#editor_id', {
                        langType&nbsp;: 'en'
                });
        });
&amp;lt;/script&amp;gt;</pre><p></p>
<ul style="color: #474747;">
<li><b>designMode</b></li>
</ul>
<p style="color: #474747;">可视化模式或代码模式</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>fullscreenMode</b></li>
</ul>
<p style="color: #474747;">true时加载编辑器后变成全屏模式。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: false</p>
<ul style="color: #474747;">
<li><b>basePath</b></li>
</ul>
<p style="color: #474747;">指定编辑器的根目录路径。</p>
<p style="color: #474747;">数据类型: String； 默认值: 根据kindeditor.js文件名自动获取</p>
<ul style="color: #474747;">
<li><b>themesPath</b></li>
</ul>
<p style="color: #474747;">指定编辑器的themes目录路径。</p>
<p style="color: #474747;">数据类型: String； 默认值: basePath + ‘themes/’</p>
<ul style="color: #474747;">
<li><b>pluginsPath</b></li>
</ul>
<p style="color: #474747;">指定编辑器的plugins目录路径。</p>
<p style="color: #474747;">数据类型: String； 默认值: basePath + ‘plugins/’</p>
<ul style="color: #474747;">
<li><b>langPath</b></li>
</ul>
<p style="color: #474747;">指定编辑器的lang目录路径。</p>
<p style="color: #474747;">数据类型: String； 默认值: basePath + ‘lang/’</p>
<ul style="color: #474747;">
<li><b>minChangeSize</b></li>
</ul>
<p style="color: #474747;">undo/redo文字输入最小变化长度，当输入的文字变化小于这个长度时不会添加到undo记录里。</p>
<p style="color: #474747;">数据类型: String； 默认值: 5</p>
<ul style="color: #474747;">
<li><b>urlType</b></li>
</ul>
<p style="color: #474747;">改变站内本地<a class="mw-redirect" style="color: #0b0080;" title="URL" href="http://www.zzbaike.com/wiki/URL">URL</a>，可设置”“、”relative”、”absolute”、”domain”。空为不修改URL，relative为相对路径，absolute为绝对路径，domain为带域名的绝对路径。</p>
<p style="color: #474747;">数据类型: String； 默认值: “”</p>
<ul style="color: #474747;">
<li><b>newlineTag</b></li>
</ul>
<p style="color: #474747;">设置回车换行标签，可设置”p”、”br”。</p>
<p style="color: #474747;">数据类型: String； 默认值: “p”</p>
<ul style="color: #474747;">
<li><b>pasteType</b></li>
</ul>
<p style="color: #474747;">设置粘贴类型，0:禁止粘贴, 1:纯文本粘贴, 2:HTML粘贴</p>
<p style="color: #474747;">数据类型: Int； 默认值: 2</p>
<ul style="color: #474747;">
<li><b>dialogAlignType</b></li>
</ul>
<p style="color: #474747;">设置弹出框(dialog)的对齐类型，可设置”“、”page”，指定page时按当前页面居中，指定空时按编辑器居中。</p>
<p style="color: #474747;">数据类型: String； 默认值: “page”</p>
<ul style="color: #474747;">
<li><b>shadowMode</b></li>
</ul>
<p style="color: #474747;">true时弹出层(dialog)显示阴影。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>useContextmenu</b></li>
</ul>
<p style="color: #474747;">true时使用右键菜单，false时屏蔽右键菜单。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>syncType</b></li>
</ul>
<p style="color: #474747;">同步数据的方式，可设置”“、”form”，值为form时提交form时自动同步，空时不会自动同步。</p>
<p style="color: #474747;">数据类型: String； 默认值: “form”</p>
<ul style="color: #474747;">
<li><b>indentChar</b></li>
</ul>
<p style="color: #474747;">wellFormatMode 为true时，HTML代码缩进字符。</p>
<p style="color: #474747;">数据类型: String； 默认值: “\t”</p>
<ul style="color: #474747;">
<li><b>cssPath</b></li>
</ul>
<p style="color: #474747;">指定编辑器iframe document的<a style="color: #0b0080;" title="CSS" href="http://www.zzbaike.com/wiki/CSS">CSS</a>文件，用于设置可视化区域的样式。</p>
<p style="color: #474747;">数据类型: String或Array； 默认值: 空</p>
<ul style="color: #474747;">
<li><b>cssData</b></li>
</ul>
<p style="color: #474747;">指定编辑器iframe document的CSS数据，用于设置可视化区域的样式。</p>
<p style="color: #474747;">数据类型: String； 默认值: 空</p>
<ul style="color: #474747;">
<li><b>bodyClass</b></li>
</ul>
<p style="color: #474747;">指定编辑器iframe document body的className。</p>
<p style="color: #474747;">数据类型: String； 默认值: “ke-content”</p>
<ul style="color: #474747;">
<li><b>colorTable</b></li>
</ul>
<p style="color: #474747;">指定取色器里的颜色。</p>
<p style="color: #474747;">数据类型: Array； 默认值:</p>
<p></p><pre class="crayon-plain-tag">[
        ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
        ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
        ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
        ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
]</pre><p></p>
<ul style="color: #474747;">
<li><b>afterCreate</b></li>
</ul>
<p style="color: #474747;">设置编辑器创建后执行的回调函数。</p>
<p style="color: #474747;">数据类型: Function； 默认值: 无</p>
<ul style="color: #474747;">
<li><b>afterChange</b></li>
</ul>
<p style="color: #474747;">编辑器内容发生变化后执行的回调函数。</p>
<p style="color: #474747;">数据类型: Function； 默认值: 无</p>
<ul style="color: #474747;">
<li><b>afterTab</b></li>
</ul>
<p style="color: #474747;">按下TAB键后执行的的回调函数。</p>
<p style="color: #474747;">数据类型: Function； 默认值: 插入4个空格的函数</p>
<ul style="color: #474747;">
<li><b>afterFocus</b></li>
</ul>
<p style="color: #474747;">编辑器聚焦(focus)时执行的回调函数。</p>
<p style="color: #474747;">数据类型: Function； 默认值: 无</p>
<ul style="color: #474747;">
<li><b>afterBlur</b></li>
</ul>
<p style="color: #474747;">编辑器失去焦点(blur)时执行的回调函数。</p>
<p style="color: #474747;">数据类型: Function； 默认值: 无</p>
<ul style="color: #474747;">
<li><b>afterUpload</b></li>
</ul>
<p style="color: #474747;">上传文件后执行的回调函数。</p>
<p style="color: #474747;">数据类型: Function； 默认值: 无</p>
<p></p><pre class="crayon-plain-tag">KindEditor.ready(function(K) {
        K.create('#id', {
                afterUpload&nbsp;: function(url) {
                        alert(url);
                }
        });
});</pre><p></p>
<ul style="color: #474747;">
<li><b>uploadJson</b></li>
</ul>
<p style="color: #474747;">指定上传文件的<a class="mw-redirect" style="color: #0b0080;" title="服务器端" href="http://www.zzbaike.com/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF">服务器端</a>程序。</p>
<p style="color: #474747;">数据类型: String； 默认值: basePath + ‘php/upload_json.php’</p>
<ul style="color: #474747;">
<li><b>fileManagerJson</b></li>
</ul>
<p style="color: #474747;">指定浏览远程图片的服务器端程序。</p>
<p style="color: #474747;">数据类型: String； 默认值: basePath + ‘php/file_manager_json.php’</p>
<ul style="color: #474747;">
<li><b>allowPreviewEmoticons</b></li>
</ul>
<p style="color: #474747;">true时鼠标放在表情上可以预览表情。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>allowImageUpload</b></li>
</ul>
<p style="color: #474747;">true时显示图片上传按钮。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>allowFlashUpload</b></li>
</ul>
<p style="color: #474747;">true时显示<a style="color: #0b0080;" title="Flash" href="http://www.zzbaike.com/wiki/Flash">Flash</a>上传按钮。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>allowMediaUpload</b></li>
</ul>
<p style="color: #474747;">true时显示视音频上传按钮。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: true</p>
<ul style="color: #474747;">
<li><b>allowFileManager</b></li>
</ul>
<p style="color: #474747;">true时显示浏览远程<a style="color: #0b0080;" title="服务器" href="http://www.zzbaike.com/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8">服务器</a>按钮。</p>
<p style="color: #474747;">数据类型: Boolean； 默认值: false</p>
<ul style="color: #474747;">
<li><b>fontSizeTable</b></li>
</ul>
<p style="color: #474747;">指定文字大小。</p>
<p style="color: #474747;">数据类型: Array； 默认值:</p>
<p></p><pre class="crayon-plain-tag">['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px']</pre><p></p>
<h2 style="color: black;"><span id=".E5.8F.82.E8.80.83.E6.9D.A5.E6.BA.90" class="mw-headline">参考来源</span></h2>
<ul style="color: #474747;">
<li>http://www.zzbaike.com/wiki/KindEditor/%E5%88%9D%E5%A7%8B%E5%8C%96%E5%8F%82%E6%95%B0</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1109</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>js+flash 剪切板复制粘贴 兼容ie chrome firefox flash10</title>
		<link>https://www.softwareace.cn/?p=1102</link>
		<comments>https://www.softwareace.cn/?p=1102#comments</comments>
		<pubDate>Thu, 08 Jan 2015 07:40:09 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1102</guid>
		<description><![CDATA[Zero Clipboard的实现原理 Zero Clipboard 利用透明的Flash让其漂浮在复制按钮之 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Zero Clipboard的实现原理</p>
<p>Zero Clipboard 利用透明的Flash让其漂浮在复制按钮之上，这样其实点击的不是按钮而是 Flash ，这样将需要的内容传入Flash，再通过Flash的复制功能把传入的内容复制到剪贴板。</p>
<p>Zero Clipboard的安装方法</p>
<p>其实也不算安装啦，就是使用前的准备工作。</p>
<p>首先需要下载 Zero Clipboard的压缩包，解压后把文件夹中两个文件：<a style="color: #929976;" href="http://www.js8.in/tag/zeroclipboard"><span style="color: #000000;">ZeroClipboard</span></a><span style="color: #000000;">.</span>js 和 ZeroClipboard.swf 放入到你的项目中。</p>
<p>然后把在你要使用复制功能的页面中引入Zero Clipboard的js文件：ZeroClipboard.js<br />
如下代码：</p>
<p>&nbsp;</p>
<div><span style="color: #66143f;">&lt;script type=&#8221;text/javascript&#8221; src=&#8221;ZeroClipboard.js&#8221;&gt;&lt;/script&gt;</span></div>
<p>注意：以上 ZeroClipboard.js, ZeroClipboard.swf需要放在同一路径下。如果不在同一路径，可使用ZeroClipboard.setMoviePath( “Flash路径” );来设置ZeroClipboard.swf 地址</p>
<p><strong>Zero Clipboard实现简单跨浏览器复制</strong></p>
<div>
<div>varclip=newZeroClipboard.Client();// 新建一个对象</div>
<div>clip.setHandCursor(true);// 设置鼠标为手型</div>
<div>clip.setText(&#8220;哈哈&#8221;);// 设置要复制的文本。</div>
<div> clip.glue(&#8220;copy-botton&#8221;);// 注册一个 button，参数为 id。点击这个 button 就会复制。这个 button 不一定要求是一个 input 按钮，也可以是其他 DOM 元素。和上一句位置不可调换</div>
</div>
<p>这样，这样基本功能实现了，点击按钮就可以复制设置好的文本了。你可能注意到了，待复制的文本是固定的，如果想要动态改变的怎么办，比如复制一个输入框中的内容。不用担心，下面会讲到的。</p>
<p>Zero Clipboard的高级功能</p>
<p><strong>1、reposition() 方法</strong></p>
<p>因为按钮上漂浮有一个 Flash 按钮，所以当页面大小发生变化时，Flash 按钮可能会错位，这样就点不着了。 不要紧，Zero Clipboard 提供了一个 reposition() 方法，可以重新计算 Flash 按钮的位置。我们可以将它绑定到 resize 事件上。如下面代码是在jQuery下实现的resize事件重新设置按钮位置：</p>
<div><span style="color: #66143f;">$</span><span style="color: #66143f;">(</span><span style="color: #66143f;">window</span><span style="color: #66143f;">)</span><span style="color: #66143f;">.</span><span style="color: #66143f;">resize</span><span style="color: #66143f;">(</span>function<span style="color: #66143f;">(</span><span style="color: #66143f;">)</span><span style="color: #66143f;">{</span><span style="color: #66143f;">clip.</span><span style="color: #66143f;">reposition</span><span style="color: #66143f;">(</span><span style="color: #66143f;">)</span><span style="color: #66143f;">;</span><span style="color: #66143f;">}</span><span style="color: #66143f;">)</span><span style="color: #66143f;">;</span></div>
<p><strong>2、hide() 和 show() 方法</strong></p>
<p>这两个方法可以隐藏和显示 Flash 按钮 。其中 show() 方法会调用 reposition() 方法。</p>
<p><strong>3、setCSSEffects() 方法</strong></p>
<p>当鼠标移到按钮上或点击时，由于有 Flash 按钮的遮挡，所以像 css “:hover”, “:active” 等伪类可能会失效。setCSSEffects() 方法就是解决这个问题。首先我们需要将伪类改成类，比如：</p>
<div><span style="color: #66143f;">#copy-botton</span><span style="color: #66143f;">:hover</span><span style="color: #66143f;">{</span>border-color<span style="color: #66143f;">:</span><span style="color: #66143f;">#FF6633</span><span style="color: #66143f;">;</span><span style="color: #66143f;">}</span><span style="color: #005916;">// 可以改成下面的</span><span style="color: #005916;">&#8220;:hover&#8221;</span><span style="color: #005916;">改成</span><span style="color: #005916;">&#8220;.hover&#8221;</span><span style="color: #005916;">#copy-botton</span><span style="color: #005916;">.hover</span><span style="color: #005916;">{</span>border-color<span style="color: #005916;">:</span><span style="color: #005916;">#FF6633</span><span style="color: #005916;">;</span><span style="color: #005916;">}</span></div>
<p>我们可以调用 clip.setCSSEffects( true ); 这样 Zero Clipboard 会自动为我们处理：将类 .hover 当成伪类 :hover 。</p>
<p><strong>4、getHTML() 方法</strong></p>
<p>如果你想自己实例一个 Flash ，不用 Zero Clipboard 的附着方法，那么这个方法就可以帮上忙了。它接受两个参数，分别为 Flash 的宽度和高度。返回的是 Flash 对应的 HTML 代码。例如：</p>
<div>var<span style="color: #66143f;">html</span><span style="color: #66143f;">=</span><span style="color: #66143f;">clip.</span><span style="color: #66143f;">getHTML</span><span style="color: #66143f;">(</span><span style="color: #66143f;">150</span><span style="color: #66143f;">,</span><span style="color: #66143f;">20</span><span style="color: #66143f;">)</span><span style="color: #66143f;">;</span></div>
<p>你可以用 innerHTML 或直接 document.write(); 进行输出。<br />
以下是测试输出的组装完毕的HTML 代码：</p>
<div>&lt;embed id=&#8221;ZeroClipboardMovie_1&#8243; src=&#8221;zeroclipboard/ZeroClipboard.swf&#8221; loop=&#8221;false&#8221; menu=&#8221;false&#8221; quality=&#8221;best&#8221; bgcolor=&#8221;#ffffff&#8221; width=&#8221;150&#8243; height=&#8221;20&#8243; name=&#8221;ZeroClipboardMovie_1&#8243; align=&#8221;middle&#8221; allowScriptAccess=&#8221;always&#8221; allowFullScreen=&#8221;false&#8221; type=&#8221;application/x-shockwave-flash&#8221; pluginspage=&#8221;http://www.macromedia.com/go/getflashplayer&#8221; flashvars=&#8221;id=1&amp;width=150&amp;height=20&#8243; wmode=&#8221;transparent&#8221; /&gt;</div>
<p>IE 的 Flash <a style="color: #929976;" href="http://www.js8.in/tag/">JavaScript</a> 通信接口上有一个 bug 。你必须插入一个 object 标签到一个已存在的 DOM 元素中。并且在写入 innerHTML 之前请确保该元素已经 appendChild 方法插入到 DOM 中。</p>
<p>Zero Clipboard 事件处理</p>
<p><strong>Zero Clipboard</strong> 提供了一些事件，你可以自定义函数处理这些事件。Zero Clipboard 事件处理函数为 addEventListener(); 例如当 Flash 完全载入后会触发一个事件 “load” 。</p>
<div>clip.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">(</span><span style="color: #3366cc;">&#8220;load&#8221;</span><span style="color: #339933;">,</span>function<span style="color: #009900;">(</span>client<span style="color: #009900;">)</span><span style="color: #009900;">{</span><span style="color: #000066;">alert</span><span style="color: #009900;">(</span><span style="color: #3366cc;">&#8220;Flash 加载完毕！&#8221;</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div>
<p>Zero Clipboard 会将 clip 对象作为参数传入。即上例中的 “client” 。<br />
还有 “load” 也可以写成 “onLoad”，其他的事件也可以这样。<br />
其他事件还包括：</p>
<p>mouseOver 鼠标移上事件<br />
mouseOut 鼠标移出事件<br />
mouseDown 鼠标按下事件<br />
mouseUp 鼠标松开事件<br />
complete 复制成功事件</p>
<p>其中 mouseOver 事件和 complete 事件比较常用。<br />
前面说过，如果需要动态改变待复制的内容，那 mouseOver 事件就可以派上用场了。例如需要动态复制一个 id 为 test 的输入框中的值，我们可以在鼠标 over 的时候重新设置值。</p>
<div>
<div>clip.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">(</span><span style="color: #3366cc;">&#8220;mouseOver&#8221;</span><span style="color: #339933;">,</span>function<span style="color: #009900;">(</span>client<span style="color: #009900;">)</span><span style="color: #009900;">{</span>var test <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">(</span><span style="color: #3366cc;">&#8220;test&#8221;</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> client.<span style="color: #660066;">setText</span><span style="color: #009900;">(</span>test.<span style="color: #660066;">value</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>// 重新设置要复制的值<span style="color: #009900;">}</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>//复制成功： clip.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">(</span><span style="color: #3366cc;">&#8220;complete&#8221;</span><span style="color: #339933;">,</span>function<span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span><span style="color: #000066;">alert</span><span style="color: #009900;">(</span><span style="color: #3366cc;">&#8220;复制成功！&#8221;</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #009900;">}</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></div>
<div><span style="color: #339933;"> </span></div>
<div><span style="color: #339933;">另外一种实现方法，和这个差不多</span></div>
<div><span style="color: #339933;">来源<a style="color: #336699;" href="http://www.lsproc.com/blog/copy_to_clipboard/">http://www.lsproc.com/blog/copy_to_clipboard/</a></span></div>
<div>
<p style="color: #373737;">从 discuz! 里扒出来的(简易实现), 代码如下:</p>
<p></p><pre class="crayon-plain-tag">var clipboardswfdata;

var setcopy_gettext = function(){
    clipboardswfdata = document.getElementById('data').value;
    window.document.clipboardswf.SetVariable('str', clipboardswfdata);
}

var floatwin = function(){
    alert('copy success, ' + clipboardswfdata);
}</pre><p>&nbsp;</p><pre class="crayon-plain-tag">&lt;input type="text" name="data" value="xxxxx11111" id ="data" /&gt;
&lt;div id="clipboard_content"&gt;
&lt;span class="clipinner" id="clipinner"&gt;点此复制到剪贴板
&lt;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"&gt;&lt;/span&gt;
&lt;/div&gt;</pre><p>&nbsp;</p><pre class="crayon-plain-tag">&lt;style type="text/css"&gt;
body {font-size:12px;}
.clipinner {position:relative;}
.clipboardswf {position:absolute; left:0; top:0;}
&lt;/style&gt;</pre><p>&nbsp;</p>
<p style="color: #373737;">演示地址: <a style="font-style: inherit; color: #1982d1;" href="http://www.lsproc.com/demo/clipboard/demo.html">http://www.lsproc.com/demo/cliboard/demo.html</a>另: 没有对ie单独处理, ie中推荐使用 window.clipboardData</p>
<p style="color: #373737;">演示代码下载: http://www.lsproc.com/wiki/_media/snippets:clipboard.zip</p>
<p style="color: #373737;">另: google code 上有个 zeroclipboard 的项目, 如果想要方便的话, 也可以使用<br />
地址: <a style="font-style: inherit; color: #1982d1;" href="http://code.google.com/p/zeroclipboard/">http://code.google.com/p/zeroclipboard/</a></p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1102</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>js RDF Parser</title>
		<link>https://www.softwareace.cn/?p=1056</link>
		<comments>https://www.softwareace.cn/?p=1056#comments</comments>
		<pubDate>Tue, 02 Dec 2014 10:38:07 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1056</guid>
		<description><![CDATA[[crayon-69f1ed8076d04840985825/] &#160;]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";
var xmlString = '&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"&gt;&lt;Description about="urn:mozilla:install-manifest"&gt;&lt;em:id&gt;PortableTester@jetpack&lt;/em:id&gt;&lt;em:version&gt;initial&lt;/em:version&gt;&lt;em:type&gt;2&lt;/em:type&gt;&lt;em:bootstrap&gt;true&lt;/em:bootstrap&gt;&lt;em:unpack&gt;false&lt;/em:unpack&gt;&lt;!--Firefox--&gt;&lt;em:targetApplication&gt;&lt;Description&gt;&lt;em:id&gt;{ec8030f7-c20a-464f-9b0e-13a3a9e97384}&lt;/em:id&gt;&lt;em:minVersion&gt;7.0&lt;/em:minVersion&gt;&lt;em:maxVersion&gt;27.0&lt;/em:maxVersion&gt;&lt;/Description&gt;&lt;/em:targetApplication&gt;&lt;!--Front End MetaData--&gt;&lt;em:name&gt;PortableTester&lt;/em:name&gt;&lt;em:description&gt;Test addon that tries to figure out if Firefox is portable or not.&lt;/em:description&gt;&lt;em:creator&gt;Noitidart&lt;/em:creator&gt;&lt;em:optionsURL&gt;options url here&lt;/em:optionsURL&gt;&lt;/Description&gt;&lt;/RDF&gt;';
var rdfParser = Cc['@mozilla.org/rdf/xml-parser;1'].createInstance(Ci.nsIRDFXMLParser);
var ds = Cc['@mozilla.org/rdf/datasource;1?name=in-memory-datasource'].createInstance(Ci.nsIRDFDataSource);

var emptyUri = Services.io.newURI('urn:none', null, null);
rdfParser.parseString(ds, emptyUri, xmlString);
var resources = ds.GetAllResources()
while (resources.hasMoreElements()) {
  let resource = resources.getNext().QueryInterface(Ci.nsIRDFResource);
  let arcs = ds.ArcLabelsOut(resource);
  while (arcs.hasMoreElements()) {
    let arc = arcs.getNext().QueryInterface(Ci.nsIRDFResource);
    let prop = arc.ValueUTF8.substring(PREFIX_NS_EM.length)
    let targets = ds.GetTargets(resource, arc, true);
    while (targets.hasMoreElements()) {
      let target = targets.getNext();
      if (target instanceof Ci.nsIRDFResource) {
        console.log(prop, "Resource node, recurse");
      }
      else if (target instanceof Ci.nsIRDFLiteral) {
        console.log(prop, target.Value); //are non ASCII characters encoded?
      }
      else if (target instanceof Ci.nsIRDFInt) {
        console.log(prop, target.Value);
      }
    }
  }
}</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1056</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
