<?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/"
	>

<channel>
	<title>一个程序猿 &#187; JS</title>
	<atom:link href="http://www.sunboyu.cn/tag/js/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sunboyu.cn</link>
	<description>时光不会倒流,脚步总要前进</description>
	<pubDate>Tue, 31 Jan 2012 10:50:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>图片动态缩放PHP与JS算法</title>
		<link>http://www.sunboyu.cn/2009/07/20/%e5%9b%be%e7%89%87%e5%8a%a8%e6%80%81%e7%bc%a9%e6%94%bephp%e4%b8%8ejs%e7%ae%97%e6%b3%95.shtml</link>
		<comments>http://www.sunboyu.cn/2009/07/20/%e5%9b%be%e7%89%87%e5%8a%a8%e6%80%81%e7%bc%a9%e6%94%bephp%e4%b8%8ejs%e7%ae%97%e6%b3%95.shtml#comments</comments>
		<pubDate>Mon, 20 Jul 2009 00:19:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[GD]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[图片缩放]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=875</guid>
		<description><![CDATA[这个算法写好多次了，虽然简单，但每次都得想一次，这里做个备份。
因为GD函数进行缩放，必须有宽和高，而在浏览器中，会自动按照比率调整宽高，所以两个函数稍有区别。
#PHP版
# $s_width&#160; 原图宽
# $s_height 原图高
# $t_width&#160; 目标文件最大宽
# $t_height 目标文件最大高
function ReSizePic( $s_width , $s_height , $t_width , $t_height)
{
	if( $s_width / $s_height &#62; $t_width / $t_height &#38;&#38; $s_width &#62; $t_width)
	{
		$t_height = $s_height * $t_width / $s_width;
		$t_width = $t_width;
	}
	else if( $s_width / $s_height &#62; $t_width / $t_height &#38;&#38; $s_width &#60; = $t_width)
	{
		$t_height = $s_height;
		$t_width&#160; = $s_width;
	}
	else if( $s_width [...]]]></description>
			<content:encoded><![CDATA[<p>这个算法写好多次了，虽然简单，但每次都得想一次，这里做个备份。</p>
<p>因为GD函数进行缩放，必须有宽和高，而在浏览器中，会自动按照比率调整宽高，所以两个函数稍有区别。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#PHP版</li>
<li># $s_width&nbsp; 原图宽</li>
<li># $s_height 原图高</li>
<li># $t_width&nbsp; 目标文件最大宽</li>
<li># $t_height 目标文件最大高</li>
<li>function ReSizePic( $s_width , $s_height , $t_width , $t_height)</li>
<li>{</li>
<li>	if( $s_width / $s_height &gt; $t_width / $t_height &amp;&amp; $s_width &gt; $t_width)</li>
<li>	{</li>
<li>		$t_height = $s_height * $t_width / $s_width;</li>
<li>		$t_width = $t_width;</li>
<li>	}</li>
<li>	else if( $s_width / $s_height &gt; $t_width / $t_height &amp;&amp; $s_width &lt; = $t_width)</li>
<li>	{</li>
<li>		$t_height = $s_height;</li>
<li>		$t_width&nbsp; = $s_width;</li>
<li>	}</li>
<li>	else if( $s_width / $s_height &lt; $t_width / $t_height &amp;&amp; $s_height &gt; $t_height)</li>
<li>	{</li>
<li>		$t_width = $s_width*$t_height/$s_height;</li>
<li>		$t_height = $t_height;</li>
<li>	}</li>
<li>	else if( $s_width / $s_height &lt; $t_width / $t_height &amp;&amp; $s_height &lt;= $t_height)</li>
<li>	{</li>
<li>		$t_height = $s_height;</li>
<li>		$t_width&nbsp; = $s_width;</li>
<li>	}</li>
<li>	return array( &quot;width&quot; =&gt; $t_width , &quot;height&quot; =&gt; $t_height );</li>
<li>}</li>
<li>#JS版</li>
<li># obj 图片对象</li>
<li># maxWidth 显示最大宽</li>
<li># maxHeight 显示最大高</li>
<li>function ReSizePic( obj , maxWidth , maxHeight )</li>
<li>{</li>
<li>	if( ( obj.width/obj.height &gt;= maxWidth/maxHeight ) &amp;&amp; obj.width &gt; maxWidth )</li>
<li>	{</li>
<li>		obj.width = maxWidth;</li>
<li>	}</li>
<li>	else if( ( obj.width/obj.height &lt; maxWidth/maxHeight ) &amp;&amp; obj.height &gt; maxHeight )</li>
<li>	{</li>
<li>		obj.height = maxHeight;</li>
<li>	}</li>
<li>}</li></ol></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2009/07/20/%e5%9b%be%e7%89%87%e5%8a%a8%e6%80%81%e7%bc%a9%e6%94%bephp%e4%b8%8ejs%e7%ae%97%e6%b3%95.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>JS:setAttribute() getAttribute() 使用总结</title>
		<link>http://www.sunboyu.cn/2008/10/07/jssetattribute-getattribute-%e4%bd%bf%e7%94%a8%e6%80%bb%e7%bb%93.shtml</link>
		<comments>http://www.sunboyu.cn/2008/10/07/jssetattribute-getattribute-%e4%bd%bf%e7%94%a8%e6%80%bb%e7%bb%93.shtml#comments</comments>
		<pubDate>Tue, 07 Oct 2008 15:53:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[dom属性]]></category>

		<category><![CDATA[JS]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=336</guid>
		<description><![CDATA[setAttribute() getAttribute() 两个函数分别是设置DOM节点属性设置和修改的函数，比如
var a=document.getElementById(&#8217;link&#8217;);
a.setAttribute(&#8217;class&#8217;) = &#8216;mylinkstyle&#8217;;
可以设置一个元素的属性
同样，我们可以自定义元素的属性，比如 &#60;a href=&#8221;#&#8221; tips=&#8221;tipscontet&#8221; title=&#8221;testtitle&#8221;&#62;test&#60;/a&#62;
如此，给a标签增加一个新的属性，tips。而tips的值可以用getAttribute()获取。
]]></description>
			<content:encoded><![CDATA[<p>setAttribute() getAttribute() 两个函数分别是设置DOM节点属性设置和修改的函数，比如</p>
<p>var a=document.getElementById(&#8217;link&#8217;);</p>
<p>a.setAttribute(&#8217;class&#8217;) = &#8216;mylinkstyle&#8217;;</p>
<p>可以设置一个元素的属性</p>
<p>同样，我们可以自定义元素的属性，比如 &lt;a href=&#8221;#&#8221; tips=&#8221;tipscontet&#8221; title=&#8221;testtitle&#8221;&gt;test&lt;/a&gt;</p>
<p>如此，给a标签增加一个新的属性，tips。而tips的值可以用getAttribute()获取。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/10/07/jssetattribute-getattribute-%e4%bd%bf%e7%94%a8%e6%80%bb%e7%bb%93.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>简单的div页面拖动效果</title>
		<link>http://www.sunboyu.cn/2008/08/07/%e7%ae%80%e5%8d%95%e7%9a%84div%e9%a1%b5%e9%9d%a2%e6%8b%96%e5%8a%a8%e6%95%88%e6%9e%9c.shtml</link>
		<comments>http://www.sunboyu.cn/2008/08/07/%e7%ae%80%e5%8d%95%e7%9a%84div%e9%a1%b5%e9%9d%a2%e6%8b%96%e5%8a%a8%e6%95%88%e6%9e%9c.shtml#comments</comments>
		<pubDate>Thu, 07 Aug 2008 15:33:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[拖动]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=250</guid>
		<description><![CDATA[这里主要是一些元素坐标的计算，不过我写这个东西不很兼容firefox，正在查找原因。
index
]]></description>
			<content:encoded><![CDATA[<p>这里主要是一些元素坐标的计算，不过我写这个东西不很兼容firefox，正在查找原因。<br />
<a href='http://www.sunboyu.cn/upfiles/2008/08/index.html'>index</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/08/07/%e7%ae%80%e5%8d%95%e7%9a%84div%e9%a1%b5%e9%9d%a2%e6%8b%96%e5%8a%a8%e6%95%88%e6%9e%9c.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>兼容ie，firefox的页面事件监听函数</title>
		<link>http://www.sunboyu.cn/2008/08/07/%e5%85%bc%e5%ae%b9ie%ef%bc%8cfirefox%e7%9a%84%e9%a1%b5%e9%9d%a2%e4%ba%8b%e4%bb%b6%e7%9b%91%e5%90%ac%e5%87%bd%e6%95%b0.shtml</link>
		<comments>http://www.sunboyu.cn/2008/08/07/%e5%85%bc%e5%ae%b9ie%ef%bc%8cfirefox%e7%9a%84%e9%a1%b5%e9%9d%a2%e4%ba%8b%e4%bb%b6%e7%9b%91%e5%90%ac%e5%87%bd%e6%95%b0.shtml#comments</comments>
		<pubDate>Thu, 07 Aug 2008 14:01:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[javescript]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[监听]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=248</guid>
		<description><![CDATA[listenerevent
//for ff
if(document.addEventListener)
{	 
&#160;&#160; &#160;function __Eventadd ( element , eventType , handle )
	{
	&#160; &#160; element.addEventListener( eventType , handle , false );
	}
	function __Eventremove ( element , eventType , handle )
	{
	&#160; &#160; element.removeEventListener( eventType , handle , false );
	}
}
//for ie
else if(document.attachEvent)
{
&#160;&#160; &#160;function __Eventadd ( element , eventType , handle )
	{
	&#160; &#160; element.attachEvent( 'on'+eventType , handle );
	}
	function __Eventremove ( [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.sunboyu.cn/upfiles/2008/08/listenerevent.js'>listenerevent</a></p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">//for ff</li>
<li>if(document.addEventListener)</li>
<li>{	 </li>
<li>&nbsp;&nbsp; &nbsp;function __Eventadd ( element , eventType , handle )</li>
<li>	{</li>
<li>	&nbsp; &nbsp; element.addEventListener( eventType , handle , false );</li>
<li>	}</li>
<li>	function __Eventremove ( element , eventType , handle )</li>
<li>	{</li>
<li>	&nbsp; &nbsp; element.removeEventListener( eventType , handle , false );</li>
<li>	}</li>
<li>}</li>
<li>//for ie</li>
<li>else if(document.attachEvent)</li>
<li>{</li>
<li>&nbsp;&nbsp; &nbsp;function __Eventadd ( element , eventType , handle )</li>
<li>	{</li>
<li>	&nbsp; &nbsp; element.attachEvent( 'on'+eventType , handle );</li>
<li>	}</li>
<li>	function __Eventremove ( element , eventType , handle )</li>
<li>	{</li>
<li>	&nbsp; &nbsp; element.detachEvent( 'on'+eventType , handle );</li>
<li>	}</li>
<li>}</li></ol></div>
<p>实际上，真正完全兼容还要很复杂的一个过程，这里也是简化到了只是能用的程度。具体请查看《JavaScript权威指南》第五版 414页</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/08/07/%e5%85%bc%e5%ae%b9ie%ef%bc%8cfirefox%e7%9a%84%e9%a1%b5%e9%9d%a2%e4%ba%8b%e4%bb%b6%e7%9b%91%e5%90%ac%e5%87%bd%e6%95%b0.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>几个JS函数，自家用，共享之</title>
		<link>http://www.sunboyu.cn/2008/08/04/%e5%87%a0%e4%b8%aajs%e5%87%bd%e6%95%b0%ef%bc%8c%e8%87%aa%e5%ae%b6%e7%94%a8%ef%bc%8c%e5%85%b1%e4%ba%ab%e4%b9%8b.shtml</link>
		<comments>http://www.sunboyu.cn/2008/08/04/%e5%87%a0%e4%b8%aajs%e5%87%bd%e6%95%b0%ef%bc%8c%e8%87%aa%e5%ae%b6%e7%94%a8%ef%bc%8c%e5%85%b1%e4%ba%ab%e4%b9%8b.shtml#comments</comments>
		<pubDate>Mon, 04 Aug 2008 10:45:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=243</guid>
		<description><![CDATA[检测浏览器类型，主要根据 userAgent关键字来确定
function __navigator()
{
&#160;&#160; &#160;this.value = false;&#160; &#160;//返回值&#160; ie 0 firefox 1 other 2
	this.useragent =&#160; navigator['userAgent'];
	if(this.useragent.indexOf('MSIE')&#62;0)
	{
	&#160; &#160; this.value = 0;
	}
	else if(this.useragent.indexOf('Firefox')&#62;0)
	{
	&#160; &#160; this.value = 1;
	}
	else
	{
	&#160; &#160; this.value = 2;
	}
}
获得浏览器相关信息
function __window()
{
&#160;&#160; &#160;this.innerwidth = 0;&#160; &#160;//document width
	this.innerheight = 0;	 //document height
&#160;
	this.outerwidth = 0;&#160; &#160;//browser width
	this.outerwidth = 0;&#160; &#160;//browser height
&#160;
	this.screenx = 0;&#160; &#160; &#160;//browser position x
	this.screeny = 0;	&#160; //browser [...]]]></description>
			<content:encoded><![CDATA[<p>检测浏览器类型，主要根据 userAgent关键字来确定</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">function __navigator()</li>
<li>{</li>
<li>&nbsp;&nbsp; &nbsp;this.value = false;&nbsp; &nbsp;//返回值&nbsp; ie 0 firefox 1 other 2</li>
<li>	this.useragent =&nbsp; navigator['userAgent'];</li>
<li>	if(this.useragent.indexOf('MSIE')&gt;0)</li>
<li>	{</li>
<li>	&nbsp; &nbsp; this.value = 0;</li>
<li>	}</li>
<li>	else if(this.useragent.indexOf('Firefox')&gt;0)</li>
<li>	{</li>
<li>	&nbsp; &nbsp; this.value = 1;</li>
<li>	}</li>
<li>	else</li>
<li>	{</li>
<li>	&nbsp; &nbsp; this.value = 2;</li>
<li>	}</li>
<li>}</li></ol></div>
<p>获得浏览器相关信息</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">function __window()</li>
<li>{</li>
<li>&nbsp;&nbsp; &nbsp;this.innerwidth = 0;&nbsp; &nbsp;//document width</li>
<li>	this.innerheight = 0;	 //document height</li>
<li>&nbsp;</li>
<li>	this.outerwidth = 0;&nbsp; &nbsp;//browser width</li>
<li>	this.outerwidth = 0;&nbsp; &nbsp;//browser height</li>
<li>&nbsp;</li>
<li>	this.screenx = 0;&nbsp; &nbsp; &nbsp;//browser position x</li>
<li>	this.screeny = 0;	&nbsp; //browser position y</li>
<li>&nbsp;</li>
<li>&nbsp;&nbsp; &nbsp;/*@cc_on</li>
<li>	&nbsp; @if(@_jscript)</li>
<li>&nbsp;</li>
<li>	&nbsp; this.innerwidth = document.body.clientWidth;</li>
<li>	&nbsp; this.innerheight = document.body.clientHeight;</li>
<li>&nbsp;</li>
<li>	&nbsp; this.outerwidth = document.documentElement.clientWidth;</li>
<li>	&nbsp; this.outerheight = document.documentElement.clientHeight;</li>
<li>	&nbsp; </li>
<li>	&nbsp; this.screenx = window.screenLeft;</li>
<li>	&nbsp; this.screeny = window.screenTop;</li>
<li>&nbsp;</li>
<li>	&nbsp; @else*/</li>
<li>&nbsp;</li>
<li>	&nbsp; this.innerwidth = window.innerWidth;</li>
<li>	&nbsp; this.innerheight = window.innerHeight;</li>
<li>&nbsp;</li>
<li>	&nbsp; this.outerwidth = window.outerWidth;</li>
<li>	&nbsp; this.outerheight = window.outerHeight;</li>
<li>&nbsp;</li>
<li>	&nbsp; this.screenx = window.screenX;</li>
<li>	&nbsp; this.screeny = window.screenY;</li>
<li>	/*@end</li>
<li>	&nbsp; @*/</li>
<li>}</li></ol></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/08/04/%e5%87%a0%e4%b8%aajs%e5%87%bd%e6%95%b0%ef%bc%8c%e8%87%aa%e5%ae%b6%e7%94%a8%ef%bc%8c%e5%85%b1%e4%ba%ab%e4%b9%8b.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript跨浏览器兼容代码</title>
		<link>http://www.sunboyu.cn/2008/08/03/javascript%e8%b7%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e5%85%bc%e5%ae%b9%e4%bb%a3%e7%a0%81.shtml</link>
		<comments>http://www.sunboyu.cn/2008/08/03/javascript%e8%b7%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e5%85%bc%e5%ae%b9%e4%bb%a3%e7%a0%81.shtml#comments</comments>
		<pubDate>Sun, 03 Aug 2008 14:58:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[兼容性]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=242</guid>
		<description><![CDATA[方法1：检测浏览器关键字
function __navigator()
{
&#160;&#160; &#160;this.value = false;&#160; &#160;//返回值&#160; ie 0 firefox 1 other 2
	this.useragent =&#160; navigator['userAgent'];
	if(this.useragent.indexOf('MSIE')&#62;0)
	{
	&#160; &#160; this.value = 0;
	}
	else if(this.useragent.indexOf('Firefox')&#62;0)
	{
	&#160; &#160; this.value = 1;
	}
	else
	{
	&#160; &#160; this.value = 2;
	}
}
方法2：
if(document.all)
&#160; ie
else
&#160; other
方法3：
&#60;!--[if IE]&#62;
&#160;&#160; &#160;js for ie
&#60;![endif]--&#62;
&#60;!--[if !IE]&#62;
&#160;&#160; &#160;js for !ie
&#60;![endif]--&#62;
方法4:
/*@cc_on
	&#160; @if(@_jscript)
	&#160; is for ie
	&#160; @else*/
	&#160; js for !ie
	/*@end
	&#160; @*/
]]></description>
			<content:encoded><![CDATA[<p>方法1：检测浏览器关键字</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">function __navigator()</li>
<li>{</li>
<li>&nbsp;&nbsp; &nbsp;this.value = false;&nbsp; &nbsp;//返回值&nbsp; ie 0 firefox 1 other 2</li>
<li>	this.useragent =&nbsp; navigator['userAgent'];</li>
<li>	if(this.useragent.indexOf('MSIE')&gt;0)</li>
<li>	{</li>
<li>	&nbsp; &nbsp; this.value = 0;</li>
<li>	}</li>
<li>	else if(this.useragent.indexOf('Firefox')&gt;0)</li>
<li>	{</li>
<li>	&nbsp; &nbsp; this.value = 1;</li>
<li>	}</li>
<li>	else</li>
<li>	{</li>
<li>	&nbsp; &nbsp; this.value = 2;</li>
<li>	}</li>
<li>}</li></ol></div>
<p>方法2：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">if(document.all)</li>
<li>&nbsp; ie</li>
<li>else</li>
<li>&nbsp; other</li></ol></div>
<p>方法3：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">&lt;!--[if IE]&gt;</li>
<li>&nbsp;&nbsp; &nbsp;js for ie</li>
<li>&lt;![endif]--&gt;</li>
<li>&lt;!--[if !IE]&gt;</li>
<li>&nbsp;&nbsp; &nbsp;js for !ie</li>
<li>&lt;![endif]--&gt;</li></ol></div>
<p>方法4:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">/*@cc_on</li>
<li>	&nbsp; @if(@_jscript)</li>
<li>	&nbsp; is for ie</li>
<li>	&nbsp; @else*/</li>
<li>	&nbsp; js for !ie</li>
<li>	/*@end</li>
<li>	&nbsp; @*/</li></ol></div>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/08/03/javascript%e8%b7%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e5%85%bc%e5%ae%b9%e4%bb%a3%e7%a0%81.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>一个操作Cookie的小程序</title>
		<link>http://www.sunboyu.cn/2008/07/30/%e4%b8%80%e4%b8%aa%e6%93%8d%e4%bd%9ccookie%e7%9a%84%e5%b0%8f%e7%a8%8b%e5%ba%8f.shtml</link>
		<comments>http://www.sunboyu.cn/2008/07/30/%e4%b8%80%e4%b8%aa%e6%93%8d%e4%bd%9ccookie%e7%9a%84%e5%b0%8f%e7%a8%8b%e5%ba%8f.shtml#comments</comments>
		<pubDate>Wed, 30 Jul 2008 14:57:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[cookie]]></category>

		<category><![CDATA[JS]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=231</guid>
		<description><![CDATA[simplecookie
&#60;br /&#62;
/*&#60;br /&#62;
&#160;&#160; &#160;一个简单的cookie操作函数，自家用&#60;br /&#62;
*/&#60;br /&#62;
function SetCookie()&#60;br /&#62;
{&#60;br /&#62;
&#160;&#160; &#160;var name = arguments[0];&#60;br /&#62;
	var value = arguments[1];&#60;br /&#62;
	//初始化默认存储时间&#60;br /&#62;
	var time = 3600;&#60;br /&#62;
	if(arguments[2]!=undefined)&#60;br /&#62;
	{&#60;br /&#62;
	&#160; &#160; time = arguments[2]&#60;br /&#62;
	}&#60;br /&#62;
	if(arguments[0]==undefined&#124;&#124;arguments[0]==undefined)&#60;br /&#62;
	{&#60;br /&#62;
	&#160; &#160; alert(&#34;SetCookie Has ERROR Agruments&#34;);&#60;br /&#62;
	}&#60;br /&#62;
	document.cookie = name+&#34;=&#34;+escape(value)+&#34; ; expires=&#34;+GetTime(time);&#60;br /&#62;
}&#60;br /&#62;
function GetCookie( name )&#60;br /&#62;
{&#60;br /&#62;
&#160;&#160; &#160;var arr = document.cookie.match(new [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sunboyu.cn/upfiles/2008/07/simplecookie.js">simplecookie</a></p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">&lt;br /&gt;</li>
<li>/*&lt;br /&gt;</li>
<li>&nbsp;&nbsp; &nbsp;一个简单的cookie操作函数，自家用&lt;br /&gt;</li>
<li>*/&lt;br /&gt;</li>
<li>function SetCookie()&lt;br /&gt;</li>
<li>{&lt;br /&gt;</li>
<li>&nbsp;&nbsp; &nbsp;var name = arguments[0];&lt;br /&gt;</li>
<li>	var value = arguments[1];&lt;br /&gt;</li>
<li>	//初始化默认存储时间&lt;br /&gt;</li>
<li>	var time = 3600;&lt;br /&gt;</li>
<li>	if(arguments[2]!=undefined)&lt;br /&gt;</li>
<li>	{&lt;br /&gt;</li>
<li>	&nbsp; &nbsp; time = arguments[2]&lt;br /&gt;</li>
<li>	}&lt;br /&gt;</li>
<li>	if(arguments[0]==undefined||arguments[0]==undefined)&lt;br /&gt;</li>
<li>	{&lt;br /&gt;</li>
<li>	&nbsp; &nbsp; alert(&quot;SetCookie Has ERROR Agruments&quot;);&lt;br /&gt;</li>
<li>	}&lt;br /&gt;</li>
<li>	document.cookie = name+&quot;=&quot;+escape(value)+&quot; ; expires=&quot;+GetTime(time);&lt;br /&gt;</li>
<li>}&lt;br /&gt;</li>
<li>function GetCookie( name )&lt;br /&gt;</li>
<li>{&lt;br /&gt;</li>
<li>&nbsp;&nbsp; &nbsp;var arr = document.cookie.match(new RegExp(&quot;(^|)&quot;+name+&quot;=([^;]*)(;|$)&quot;));&lt;br /&gt;</li>
<li>	if(arr!=null)&lt;br /&gt;</li>
<li>	{&lt;br /&gt;</li>
<li>	&nbsp; &nbsp; return unescape(arr[2]);&lt;br /&gt;</li>
<li>	}&lt;br /&gt;</li>
<li>	else&lt;br /&gt;</li>
<li>	{&lt;br /&gt;</li>
<li>	&nbsp; &nbsp; return null;&lt;br /&gt;</li>
<li>	}&lt;br /&gt;</li>
<li>}&lt;br /&gt;</li>
<li>function DelCookie( name )&lt;br /&gt;</li>
<li>{&lt;br /&gt;</li>
<li>&nbsp;&nbsp; &nbsp;var value = GetCookie( name );&lt;br /&gt;</li>
<li>	if(value!=null)&lt;br /&gt;</li>
<li>	{&lt;br /&gt;</li>
<li>	&nbsp; &nbsp; document.cookie = name+&quot;=&quot;+escape(value)+&quot; ; expires=&quot;+GetTime( 0 );&lt;br /&gt;</li>
<li>	}&lt;br /&gt;</li>
<li>}&lt;br /&gt;</li>
<li>function GetTime( time )&lt;br /&gt;</li>
<li>{&lt;br /&gt;</li>
<li>&nbsp;&nbsp; &nbsp;var exp = new Date();&lt;br /&gt;</li>
<li>	exp.setTime( exp.getTime()+time*1000 );&lt;br /&gt;</li>
<li>	return exp.toGMTString();&lt;br /&gt;</li>
<li>}&lt;br /&gt;</li></ol></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/07/30/%e4%b8%80%e4%b8%aa%e6%93%8d%e4%bd%9ccookie%e7%9a%84%e5%b0%8f%e7%a8%8b%e5%ba%8f.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>用户行为状态的持久化</title>
		<link>http://www.sunboyu.cn/2008/07/30/%e7%94%a8%e6%88%b7%e8%a1%8c%e4%b8%ba%e7%8a%b6%e6%80%81%e7%9a%84%e6%8c%81%e4%b9%85%e5%8c%96.shtml</link>
		<comments>http://www.sunboyu.cn/2008/07/30/%e7%94%a8%e6%88%b7%e8%a1%8c%e4%b8%ba%e7%8a%b6%e6%80%81%e7%9a%84%e6%8c%81%e4%b9%85%e5%8c%96.shtml#comments</comments>
		<pubDate>Wed, 30 Jul 2008 04:41:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[原创技术]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[持久]]></category>

		<category><![CDATA[行为]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=230</guid>
		<description><![CDATA[用持久化这个词，有点拽文的意思，但必须找出一个形象的词汇来描述，暂且这么用。
用户行为持久，主要指保留用户行为状态，比如保存用户的登录信息，可以让用户不必每次输入密码。保留用户当前打开的页面，当前对客户端的操作等。
用户登录状态，主要应用cookie的方式把一些认证信息保存在本地，而其他信息的保留，同样可以使用cookie保存，比如框架的一些状态。
http://openoa.sunboyu.cn   这个网站中，可以看一下对用户行为持久的一些操作。首先是框架左侧菜单显示的控制。这个控制可以在刷新的时候保持用户的折叠状态，而不用每次刷新，都去折叠菜单。这个控制用cookie保存数据。
还有个操作，就是曾经另我很头疼的，大框架每刷新一次，主框架都会恢复默认的链接，也就是中间打开的页面会丢失。最近用js解决了这个问题，每次点击左侧菜单链接的时候，使用锚点标记的方式把链接写在url中，再次刷新的时候，根据url中的锚点确认主框架的链接。
这两个功能都完成了，用着还不错。
]]></description>
			<content:encoded><![CDATA[<p>用持久化这个词，有点拽文的意思，但必须找出一个形象的词汇来描述，暂且这么用。</p>
<p>用户行为持久，主要指保留用户行为状态，比如保存用户的登录信息，可以让用户不必每次输入密码。保留用户当前打开的页面，当前对客户端的操作等。</p>
<p>用户登录状态，主要应用cookie的方式把一些认证信息保存在本地，而其他信息的保留，同样可以使用cookie保存，比如框架的一些状态。</p>
<p>http://openoa.sunboyu.cn   这个网站中，可以看一下对用户行为持久的一些操作。首先是框架左侧菜单显示的控制。这个控制可以在刷新的时候保持用户的折叠状态，而不用每次刷新，都去折叠菜单。这个控制用cookie保存数据。</p>
<p>还有个操作，就是曾经另我很头疼的，大框架每刷新一次，主框架都会恢复默认的链接，也就是中间打开的页面会丢失。最近用js解决了这个问题，每次点击左侧菜单链接的时候，使用锚点标记的方式把链接写在url中，再次刷新的时候，根据url中的锚点确认主框架的链接。</p>
<p>这两个功能都完成了，用着还不错。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/07/30/%e7%94%a8%e6%88%b7%e8%a1%8c%e4%b8%ba%e7%8a%b6%e6%80%81%e7%9a%84%e6%8c%81%e4%b9%85%e5%8c%96.shtml/feed</wfw:commentRss>
		</item>
		<item>
		<title>死苛正则表达式</title>
		<link>http://www.sunboyu.cn/2008/06/27/%e6%ad%bb%e8%8b%9b%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f.shtml</link>
		<comments>http://www.sunboyu.cn/2008/06/27/%e6%ad%bb%e8%8b%9b%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f.shtml#comments</comments>
		<pubDate>Fri, 27 Jun 2008 04:57:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[感悟]]></category>

		<category><![CDATA[JS]]></category>

		<category><![CDATA[正则]]></category>

		<guid isPermaLink="false">http://www.sunboyu.cn/?p=160</guid>
		<description><![CDATA[犀牛书买来后，先看的正则。
正则就是一堆逻辑规则的集合，没啥难的，类似语句中的if else foreach等，只是把语句换乘符号了。
首先得会拆解逻辑，而后用那些乱七八糟的符号去描述这些逻辑。
规则是人家定的，没办法，只好用这些东西。
进步很快，希望能称谓正则高手。
]]></description>
			<content:encoded><![CDATA[<p>犀牛书买来后，先看的正则。</p>
<p>正则就是一堆逻辑规则的集合，没啥难的，类似语句中的if else foreach等，只是把语句换乘符号了。</p>
<p>首先得会拆解逻辑，而后用那些乱七八糟的符号去描述这些逻辑。</p>
<p>规则是人家定的，没办法，只好用这些东西。</p>
<p>进步很快，希望能称谓正则高手。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sunboyu.cn/2008/06/27/%e6%ad%bb%e8%8b%9b%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f.shtml/feed</wfw:commentRss>
		</item>
	</channel>
</rss>

