<?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; Js/AJAX</title>
	<atom:link href="http://pwwang.com/tag/js-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://pwwang.com</link>
	<description>专注技术,用心生活!</description>
	<lastBuildDate>Fri, 03 Sep 2010 08:13:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>简单写了个jquery的鼠标提示文字插件</title>
		<link>http://pwwang.com/technology/js-javascript/jquery_tip/</link>
		<comments>http://pwwang.com/technology/js-javascript/jquery_tip/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 01:51:07 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=968</guid>
		<description><![CDATA[&#160;

效果图:



<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/jquery_tip/" title="简单写了个jquery的鼠标提示文字插件">Read More: 1137 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>效果图:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/08/jquery.tip_.js.jpg"><img width="347" height="198" title="jquery.tip.js" src="http://pwwang.com/wp-content/uploads/2010/08/jquery.tip_.js.jpg" style="clear: both;" alt="" /></a></p>
<p><span id="more-968"></span>调用:</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;js/jquery.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;js/jquery.tip.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
$(function(){
    $('div').tip('This is a multipul style tip. I\'m <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;font</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;font-weight:bold&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>bold<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/font<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>Line break. I\'m <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;font</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;color:red&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>red<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/font<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>. Images are also availale. <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://pwwang.com/logo.gif&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>');
});
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;float:left; width:300px; height:300px; background:#f90;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>handler<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</p>
<p>源码:</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    $.<span style="color: #660066;">tip</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>src<span style="color: #339933;">,</span> content<span style="color: #339933;">,</span> cls<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> $tdiv <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $tdiv.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">'position'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'absolute'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'display'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'z-index'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'9999'</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> cls <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $tdiv.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>cls<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            $tdiv.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">'border'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'1px solid #969696'</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">'background'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'#ffe'</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">'font-size'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'12px'</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">'padding'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'2px'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> move <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $tdiv.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">'top'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageY</span><span style="color: #339933;">+</span><span style="color: #CC0000;">23</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">'left'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageX</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        $<span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseenter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $tdiv.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mousemove'</span><span style="color: #339933;">,</span> move<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        $<span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseleave</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $tdiv.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mousemove'</span><span style="color: #339933;">,</span> move<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// content: what is the tip</span>
    <span style="color: #006600; font-style: italic;">// cls: the style class of the tip div</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">tip</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>content<span style="color: #339933;">,</span> cls<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">new</span> $.<span style="color: #660066;">tip</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> content<span style="color: #339933;">,</span> cls<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>    
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/jquery_tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>谈HTML表单元素的一种写法</title>
		<link>http://pwwang.com/technology/js-javascript/talk_about_an_insertion_of_html_form/</link>
		<comments>http://pwwang.com/technology/js-javascript/talk_about_an_insertion_of_html_form/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 07:38:43 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=964</guid>
		<description><![CDATA[&#160;

默认的表单(form)是有margin的, 所以插入的时候, 可能会使布局变形.

有时候表单内的元素较多, 需要排版, 较为方便的还是table.

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/talk_about_an_insertion_of_html_form/" title="谈HTML表单元素的一种写法">Read More: 921 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>默认的表单(form)是有margin的, 所以插入的时候, 可能会使布局变形.</p>
<p>有时候表单内的元素较多, 需要排版, 较为方便的还是table.</p>
<p>为了消除表单给页面布局带来的影响, 我常常喜欢这样插入表单:</p>
<p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;?&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;form1&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;form1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</p>
<p><span id="more-964"></span></p>
<p>这样就没有表单带来的布局影响了.</p>
<p>然而, 当我用js来操作时, IE下影响不大, 但在FF下就出现问题了:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#form1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//用纯js操作效果是一样的</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>IE下正常,可以得到表单的innerHTML, 但FF下却为空.</p>
<p>如果我用js在表单中插入一个元素, 但来alert,发现只有插入的那个元素的html:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#form1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input type=&quot;text&quot; name=&quot;textfield&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#form1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//FF中结果是&lt;input type=&quot;text&quot; name=&quot;textfield&quot; &gt;</span>
<span style="color: #006600; font-style: italic;">//ie中可以得到原有元素加上插入的元素的html</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>查看源代码发现, 原来FF把form的结束tag解释在了开始tag之后:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;?&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;form1&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;form1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tbody<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;textfield&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tbody<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p>故而form的innerHTML为空.</p>
<p>正确的写法应该是这样的:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /*可在css文件中定义*/
form{margin:0; padding0;}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;?&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;form1&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;form1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/talk_about_an_insertion_of_html_form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mine-Sweeping(扫雷) in jQuery/JavaScript</title>
		<link>http://pwwang.com/technology/js-javascript/mine-sweeping-in-jqueryjavascript/</link>
		<comments>http://pwwang.com/technology/js-javascript/mine-sweeping-in-jqueryjavascript/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:01:09 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[扫雷]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=772</guid>
		<description><![CDATA[Demo:&#160;&#160; http://pwwang.com/tools/mine-sweeping.html

Google Code Project Home Page:&#160; http://code.google.com/p/mine-sweep-in-jquery-javascript/



<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/mine-sweeping-in-jqueryjavascript/" title="Mine-Sweeping(扫雷) in jQuery/JavaScript">Read More: 616 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://pwwang.com/tools/mine-sweeping.html"><img title="Mine_Sweeping_in_jQuery_JavaScript" border="0" alt="Mine_Sweeping_in_jQuery_JavaScript" width="650" height="418" style="clear: both" src="http://pwwang.com/wp-content/uploads/2009/10/Mine_Sweeping_in_jQuery_JavaScript.png" /></a></p>
<p><strong><big>Demo:</big></strong>&nbsp;&nbsp; <a target="_blank" href="http://pwwang.com/tools/mine-sweeping.html">http://pwwang.com/tools/mine-sweeping.html</a></p>
<p><big><strong>Google Code Project Home Page:&nbsp; </strong></big><a target="_blank" href="http://code.google.com/p/mine-sweep-in-jquery-javascript/">http://code.google.com/p/mine-sweep-in-jquery-javascript/</a></p>
<p><span id="more-772"></span></p>
<h1>Introduction</h1>
<p>A simulation of windows mine-sweeping(扫雷) in jQuery/JavaScript<a href="/p/mine-sweep-in-jquery-javascript/w/edit/JavaScript">?</a></p>
<h1>Information</h1>
<p>pwwang <a rel="nofollow" href="http://pwwang.com">http://pwwang.com</a></p>
<p>page <a rel="nofollow" href="http://pwwang.com/technology/js-javascript/mine-sweeping-in-jquery-javascript/">http://pwwang.com/technology/js-javascript/mine-sweeping-in-jquery-javascript/</a></p>
<p>demo <a rel="nofollow" href="http://pwwang.com/tools/mine-sweeping.html">http://pwwang.com/tools/mine-sweeping.html</a></p>
<h1>Details</h1>
<ul>
<li>Performs perfectly in Firefox</li>
<li>Works well in IE but not ideally</li>
<li>Basicly realize all the functions of all windows mine-sweeping has</li>
<li>Especially realize an event that the left-button and right-button clicks at the &quot;same&quot; time &#8212;- that is, it differs in a very short time,and then the event will fire.</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/mine-sweeping-in-jqueryjavascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript中左右键“同时”点击(click,mousedown,mouseup)事件</title>
		<link>http://pwwang.com/technology/js-javascript/left-right-simultaneously-click-in-javascript/</link>
		<comments>http://pwwang.com/technology/js-javascript/left-right-simultaneously-click-in-javascript/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 01:35:09 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[左右键同时点击]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=760</guid>
		<description><![CDATA[&#160;

之所以同时加上引号，是因为真正的同时，除了机器人，是不可能做到的。

这个是利用jQuery的事件管理机制来实现的，并把它写成了一个jQuery插件。

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/left-right-simultaneously-click-in-javascript/" title="JavaScript中左右键“同时”点击(click,mousedown,mouseup)事件">Read More: 3939 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>之所以同时加上引号，是因为真正的同时，除了机器人，是不可能做到的。</p>
<p>这个是利用jQuery的事件管理机制来实现的，并把它写成了一个jQuery插件。</p>
<p>在Firefox中表现完美， 在IE中能够实现想要的功能，但是总是有些不尽如人意。</p>
<p>在IE中左键的button值是1,右键是0；而在Firefox中左键是0,右键是2.</p>
<p>问题倒不在这里，问题在于，如果你在IE中先点右键，再很短的时间内再点左键，你会发现得到的button值是3！并且如果是这么简单也就好了，直接检测button值，如果是3,就直接执行事件就行了。可是问题总不是想象中的那样简单，在button＝3的事件执行完之后，IE还会激发一个button=1的事件（先点的右键，那点的左键）。这在处理起来就麻烦多了。</p>
<p>我的思路和网上想实现这类功能的人的思路大致相同，也是通过一个计时器来判断。</p>
<p>具体思路是这样的：</p>
<p><span id="more-760"></span>这个插件可以处理鼠标左右键的同时点击（click），鼠标按下（mousedown），鼠标弹起（mouseup）事件。在讲思路的时候就以点击为</p>
<p>例。</p>
<p>首先我们必须先找出所有绑定为点击的事件，unbind它们，因为要阻止它们在一点击鼠标的时候就执行。</p>
<p>在找这些事件的时候还是颇费了一番功夫的。因为jQuery的源码还没有真正的读通。所以机制也并没有弄很清楚明白。jQuery将事件存在了一个缓存里面（jQuery.cache），但是如果从这个缓存里把这些事件取出来？关键问题是找到元素对应的在缓存的位置，我找遍了jQuery(&#8230;)就是没有这样的公有方法。于是用了一个小trick，我们知道jQuery允许我们给一个元素绑定data，而这个data也是存在缓存里的。所以我就可以赋一个唯一的属性值给data（时间戳或者随机数），再后再通过这个唯一值找到这个元素并找到存储的事件。</p>
<p>这时候我们就可以处理左右键的事件了。因为无论左键还是右键先点，我们要达到的效果是一样的，所以这里只说一下其中一个键点击的事件。</p>
<p>当点击一个键的时候，我们先需要先判断另一个键是否已经点击，如果还没有点击，这时候判断一下时间差（这个是专为IE设计的。。。因为IE会引起一个button=1的事件，在button＝3的事件执行之后，就把时间变量设置为当前时间），如果不在时间差内，就等待另一个按键的点击。如果另一个键已经点击了的话，那就直接判断时间差，在时间差内就执行给定的事件；如果不在，就执行原有的事件。</p>
<p><span style="color: rgb(153, 51, 0);">这样，在bindLR后，也不影响原来已经bind的事件的执行（会有设定时间的延时，为了等待另一个键的点击），在unbindLR之后，也能够恢复原来已经bind的事件，我没有采用循环绑定，所以在绑定了bindLR事件之后，无法再用unbind来原有事件的绑定，并且，unbindLR现在的功能有限，只能解除所有的bindLR事件，并不能解除指定事件的绑定。</span></p>
<p>jquery.LRmouse.js</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 *
 * jquery.LRmouse 1.0.0
 * 
 * Author: pwwang ( http://pwwang.com )
 * 2009.10.26
 *
 * Bind an event handle to a listener that 
 * LButton and RButton of the mouse act
 * ( click, mousedown, mouseup ) &quot;simultaneously&quot;
 *
 * It works on both IE and Firefox, distinguishedly,
 * however, it performs perfectly in Firefox; not
 * exactly ideally in IE.
 *
 **/</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    $.<span style="color: #660066;">bindLR</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> elem<span style="color: #339933;">,</span> type<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> fn<span style="color: #339933;">,</span> intv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> L_BUTTON <span style="color: #339933;">=</span> $.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> R_BUTTON <span style="color: #339933;">=</span> $.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">;</span>    
        <span style="color: #003366; font-weight: bold;">var</span> LR_BUTTON <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// ie</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> orgType <span style="color: #339933;">=</span> type.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> L_flag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> R_flag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>                
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> getTime <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">+</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>        
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> lrId <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// for finding the elem in $.cache</span>
        <span style="color: #006600; font-style: italic;">// a trick, 'cz I don't know how to</span>
        <span style="color: #006600; font-style: italic;">// find the function directly</span>
        elem.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lrId'</span><span style="color: #339933;">,</span> lrId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
        <span style="color: #003366; font-weight: bold;">var</span> orgFns <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> $.<span style="color: #660066;">cache</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  
        <span style="color: #006600; font-style: italic;">// find original binded functions</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $.<span style="color: #660066;">cache</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'lrId'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> lrId <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> fns <span style="color: #339933;">=</span> $.<span style="color: #660066;">cache</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'events'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>orgType<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #000066; font-weight: bold;">in</span> fns <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    orgFns.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> fns<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    elem.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span> orgType<span style="color: #339933;">,</span> fns<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #006600; font-style: italic;">//remove it</span>
                elem.<span style="color: #660066;">removeData</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lrId'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        elem.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lrTempEvents'</span><span style="color: #339933;">,</span>orgFns<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> timer <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> timeOut<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> reset <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            L_flag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            R_flag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            clearTimeout<span style="color: #009900;">&#40;</span> timeOut <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>        
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> orgFnHandle <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            reset<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>orgFns.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                orgFns<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> L_event <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>R_flag <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//waiting</span>
                <span style="color: #006600; font-style: italic;">// if LR_BUTTON, do NOT wait</span>
                <span style="color: #006600; font-style: italic;">// LR_BUTTON in ie will call L_BUTTON event</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> timer <span style="color: #339933;">&gt;</span> intv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  
                    L_flag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    timer <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    timeOut <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span> 
                        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>orgFnHandle<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
                        intv<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                reset<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> deltT <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> timer<span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> deltT <span style="color: #339933;">&lt;=</span> intv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    fn.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    orgFnHandle<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> R_event <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>L_flag <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> timer <span style="color: #339933;">&gt;</span> intv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    R_flag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    timer <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    timeOut <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span> 
                        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>orgFnHandle<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
                        intv<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
                reset<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> deltT <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>timer<span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> deltT <span style="color: #339933;">&lt;=</span> intv <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    fn.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    orgFnHandle<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> eventHandle <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> L_BUTTON <span style="color: #339933;">===</span> e.<span style="color: #660066;">button</span> <span style="color: #009900;">&#41;</span>
                L_event <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> R_BUTTON <span style="color: #339933;">===</span> e.<span style="color: #660066;">button</span> <span style="color: #009900;">&#41;</span>
                R_event <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> LR_BUTTON <span style="color: #339933;">===</span> e.<span style="color: #660066;">button</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//ie</span>
                timer <span style="color: #339933;">=</span> getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                fn.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>    
&nbsp;
        <span style="color: #006600; font-style: italic;">//ban context menu;</span>
        elem.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contextmenu'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
        <span style="color: #006600; font-style: italic;">//bind new</span>
        elem.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span> orgType<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> eventHandle <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    $.<span style="color: #660066;">unbindLR</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span> type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        elem.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contextmenu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        elem.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span> type <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> orgType <span style="color: #339933;">=</span> type.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        elem.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span> orgType <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> lrId <span style="color: #339933;">=</span> Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        elem.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lrId'</span><span style="color: #339933;">,</span> lrId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> $.<span style="color: #660066;">cache</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $.<span style="color: #660066;">cache</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'lrId'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> lrId <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> fns <span style="color: #339933;">=</span> $.<span style="color: #660066;">cache</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'lrTempEvents'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #000066; font-weight: bold;">in</span> fns <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    elem.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span> orgType<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> fns<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>elem<span style="color: #339933;">,</span>arguments<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #006600; font-style: italic;">//remove it</span>
                elem.<span style="color: #660066;">removeData</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lrId'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                elem.<span style="color: #660066;">removeData</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lrTempEvents'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">bindLR</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> fn<span style="color: #339933;">,</span> intv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $.<span style="color: #660066;">isFunction</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            intv <span style="color: #339933;">=</span> fn <span style="color: #339933;">||</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span>
            fn <span style="color: #339933;">=</span> data<span style="color: #339933;">;</span>
            data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            data <span style="color: #339933;">=</span> data <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            fn <span style="color: #339933;">=</span> fn <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            intv <span style="color: #339933;">=</span> intv <span style="color: #339933;">||</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #006600; font-style: italic;">// lr bind for $(...).trigger()</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span>data<span style="color: #339933;">,</span>fn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> type.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'lr'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $.<span style="color: #660066;">bindLR</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> type<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> fn<span style="color: #339933;">,</span> intv <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">unbindLR</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">unbindLR</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>type <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/left-right-simultaneously-click-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript中的print_r</title>
		<link>http://pwwang.com/technology/js-javascript/print_r-in-javascript/</link>
		<comments>http://pwwang.com/technology/js-javascript/print_r-in-javascript/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 16:59:03 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=754</guid>
		<description><![CDATA[&#160;

做JavaScript开发, 特别是稍微复杂一点的程序, 难免要用到JavaScript面对对象的特性, 现在JavaScript的调试工具逐渐多和强大起来, 然而有时候要看一个object的值, 还是很不方便, 这时候就开始想念php的print_r功能了, 它可以将数组和对象的皮剥得干干净净, 让你看得一清二楚.

网上已经有很多版本了,但都不太好用,没有达到想要的效果,我自己写了一个, 稍微看得清楚一点.

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/print_r-in-javascript/" title="JavaScript中的print_r">Read More: 1151 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>做JavaScript开发, 特别是稍微复杂一点的程序, 难免要用到JavaScript面对对象的特性, 现在JavaScript的调试工具逐渐多和强大起来, 然而有时候要看一个object的值, 还是很不方便, 这时候就开始想念php的print_r功能了, 它可以将数组和对象的皮剥得干干净净, 让你看得一清二楚.</p>
<p>网上已经有很多版本了,但都不太好用,没有达到想要的效果,我自己写了一个, 稍微看得清楚一点.</p>
<p>先看一下效果图:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/js_print_r.png"><img width="396" height="465" border="0" title="js_print_r" alt="js_print_r" src="http://pwwang.com/wp-content/uploads/2009/10/js_print_r.png" style="clear: both;" /></a></p>
<p>图中我只截取了一个元素,下面还有几个元素没有截取, 从这张图中可以看出来这个object的结构是:</p>
<p><span style="font-family: Courier New;">[ <br />
&nbsp;&nbsp; {&nbsp; events: { <br />
&nbsp;&nbsp;&nbsp; unload: [ function(){...} ],<br />
&nbsp; &nbsp; load: [ function(){...} ]<br />
&nbsp;&nbsp; } },<br />
&nbsp; { &#8230; }<br />
]</span></p>
<p><span id="more-754"></span>功能特色:</p>
<p>1. 同一父级下的子元素,不同的层级显示不同的字体颜色</p>
<p>2. 同一层级的开始和结束的地方用 | 连接, 极好辩认</p>
<p>3. 显示数据类型</p>
<p>4. 如果类型是函数的话, 格式保持不变( IE和firefox下表现不同, 但能保持格式 )</p>
<p>&nbsp;源代码:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> print_r<span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        i <span style="color: #339933;">=</span> i <span style="color: #339933;">||</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// how many tabs</span>
        <span style="color: #003366; font-weight: bold;">var</span> color <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'00000'</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>0x1000000<span style="color: #339933;">&lt;&lt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #006600; font-style: italic;">// randomly generate a color</span>
        <span style="color: #003366; font-weight: bold;">var</span> indent <span style="color: #339933;">=</span> <span style="color: #3366CC;">'|    '</span>
        <span style="color: #006600; font-style: italic;">// form of a tab, you can use '|\t' instead</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> space <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> k<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> k<span style="color: #339933;">&lt;</span>i<span style="color: #339933;">;</span> k<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            space <span style="color: #339933;">+=</span> indent<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #000066; font-weight: bold;">in</span> o <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> val <span style="color: #339933;">=</span> o<span style="color: #009900;">&#91;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>   
            ret <span style="color: #339933;">+=</span> space <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;font style=&quot;color:'</span> <span style="color: #339933;">+</span> color <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; =&gt; &quot;</span><span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">'( &lt;/font&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> val <span style="color: #339933;">==</span> <span style="color: #3366CC;">'object'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                ret <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">+</span><span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">,</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                ret <span style="color: #339933;">+=</span> space<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> val <span style="color: #339933;">==</span> <span style="color: #3366CC;">'function'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                ret <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> space <span style="color: #339933;">+</span> indent <span style="color: #339933;">+</span> val.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\n/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">+</span>space<span style="color: #339933;">+</span>indent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">+</span>space<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span>
                ret <span style="color: #339933;">+=</span> val <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">;</span>
            ret <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;font style=&quot;color:'</span> <span style="color: #339933;">+</span> color <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">')&lt;/font&gt;<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> o <span style="color: #339933;">==</span> <span style="color: #3366CC;">'object'</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&lt;pre&gt;'</span><span style="color: #339933;">+</span><span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//use pre to prevent structure destruction</span>
    <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/print_r-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tetris(俄罗斯方块) in jQuery/JavaScript!</title>
		<link>http://pwwang.com/technology/js-javascript/tetris-in-jquery-javascript/</link>
		<comments>http://pwwang.com/technology/js-javascript/tetris-in-jquery-javascript/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 18:09:48 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tetris]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=746</guid>
		<description><![CDATA[&#160;

All in jQuery/JavaScript + HTML!

Demo：Tetris(俄罗斯方块) in jQuery/JavaScript!

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/tetris-in-jquery-javascript/" title="Tetris(俄罗斯方块) in jQuery/JavaScript!">Read More: 2427 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>All in jQuery/JavaScript + HTML!</p>
<p>Demo：<a target="_blank" href="http://pwwang.com/tools/tetris.html">Tetris(俄罗斯方块) in jQuery/JavaScript!</a></p>
<p>文章最后会给出源码下载。</p>
<p>先上两张图：</p>
<p><a href="http://pwwang.com/tools/tetris.html" target="_blank"><img border="0" style="clear: both;" src="http://pwwang.com/wp-content/uploads/tetris/Tetris_ready.png" alt="" /></a></p>
<p><a href="http://pwwang.com/tools/tetris.html" target="_blank"><img border="0" style="clear: both;" src="http://pwwang.com/wp-content/uploads/tetris/Tetris_running.png" alt="" /></a></p>
<p><span id="more-746"></span></p>
<p>其实很早就有这样的想法，无奈思想一直不是很成熟，各个细节没有想好。突然某一天灵光闪现，就想到办法了。相信应该也有很多人有过这样的想法，可是总是会被一些细节问题所卡住。只要思路有了，代码的实现上并不难。所以我重点说一下思路。</p>
<p>先说一下这样程序的功能吧。图里面能够看得很清楚了。基本的功能就不说了，其它的包括下一个下落形状的预览（左上角的小方块中），隐藏、显示网格线，隐藏、显示下落时对好的阴影形状。其它的就是俄罗斯方块的基本功能了。</p>
<p>很重要的一点，很多人可能受到了思维定势的影响，觉得既然是俄罗斯方块，那当然是一个个方块往下落。如果你这样想，我敢说这样就算程序的功能都可以完成，也绝对在1000行以上（我的程序不超过1000行，包括各个函数的注释），甚至要远远超过这个数。如果跳出了这个方块下落和思维定势，那问题就好解决了。</p>
<p>有人可能要问了，既然方块不动，那是什么在动呢？有人说颜色，但更确切地说是样式！每一次，让下一个方格的样式用上一个方块来替代，这样下落就成了对样式的操作了！虽然下落是位置在变，位置（top,left）也是样式，但是这可能要涉及到HTML，或者DOM元素的操作了。相比而言，前一种思路不用动任何的HTML元素！这是简化的最关键所在了。</p>
<p>再说一下其它方面。</p>
<p>方块的排列：</p>
<p>用一个float:left就能排列好了，需要注意的是，在设置容器的长宽时，要注意小方块的方框宽度，这个也要计算在内。</p>
<p>按键的处理：</p>
<p>我们知道，像DIV，SPAN（容器用的DIV，方块用的SPAN）无法直接响应按键按下的事件（onkeydown），那我们只好先用可以响应的元素来接收这个事件，我用的是document，由于我把它写在了类的内部，所以，要把事件内容的this变成实际要处理的元素（Tetris），就需要用到javascript的call函数了。</p>
<p>形状在移动（左、右、下、旋转）的时候出界或者是否压住了其他方块的判断：</p>
<p>有两种方式，第一种是先计算好方块可以移动的最小距离，然后再判断方块是否移动超过了这个最小距离。（注意我这里说的移动都是对样式的操作）。这种方式比较麻烦，因为首先要得到方块的最左，最右和最下的方块，然后再通过这些方块来计算这个最小距离，并且旋转就无法用距离来衡量了。但是如果要得到阴影（后面解释阴影的实现）的话，还是得计算这个最小距离。我的做法是移动一步（包括旋转）采取第二种方法，而直接下落和生成阴影而采用第一种方法。</p>
<p>第二种方式是先将坐标值预存起来，然后假设方块移动了，再判断这个方块是否在界内，并没在压住其它的方块。如果不符合条件，再将坐标值还原回去。这里插一句，如果预存坐标？我的坐标采用的是数组的形式储存的，不能直接用＝来赋值，这个只能将变量指向右值而成为右值的引用。要复制数组或对象，必须采用循环或者遍历对象属性，且元素或属性的值为基本类型时才能赋值。</p>
<p>下一个形状预览的问题：</p>
<p>想清楚了最关键的问题，这个问题很好解决，这个就是大容器的缩小版，当前显示形状的时候同时计算下一个形状的序列号，并存储。下次显示形状的时候调用这个序列号就行了。</p>
<p>最后说一下旋转的问题：</p>
<p>其实这是一个数学问题。</p>
<p><img border="0" alt="" src="http://pwwang.com/wp-content/uploads/tetris/rotate.gif" style="clear: both;" /></p>
<p>由于旋转前后，向量的长度（设为R）不变，所以：</p>
<p>cosA = x0/R,&nbsp; sinA = y0/R&nbsp;&nbsp;&nbsp;&nbsp; &#8230;&#8230; &nbsp; （2）</p>
<p>对于右图：</p>
<p>x1 = R * cos（A+B）＝R（cosAcosB &#8211; sinAsinB）</p>
<p>y1 = R|* sin（A+B）＝R（sinAcosB + cosAsinB）</p>
<p>将（2）代入得到：</p>
<p>x1 = x0 * cosB &#8211; y0 * sinB</p>
<p>y1 = x0 * sinB + y0 * cosB</p>
<p>由于我设定的是逆时针旋转，所以再将B＝-B代入上式：</p>
<p>x1 = x0 * cosB + y0 * sinB</p>
<p>y1 = -x0 * sinB + y0 * cosB</p>
<p>再者，我们旋转的角度为90度，再代入，得到：</p>
<p>x1=y0, y1=-x0&nbsp;&nbsp; &#8230;&#8230;&#8230;&#8230;. （3）</p>
<p>这是以原点为出发的向量，如果不是原点为出发点，假设这个点（旋转中心）为（cx，cy），将向量进行平移：</p>
<p>x1-cx = y0-cy, y1-cy = cx-x0，于是（3）变成：</p>
<p>x1 = cx-cy+y0, y1 = cx+cy-x0&nbsp; （4）</p>
<p>这里值得提一下的是，尽管我们的坐标系和正规的xy平面坐标系不同，我们的原点在左上角，x（二维数组第一下标）轴垂直向下，y（二维数组第二下标）轴水平向右，但是由于我们旋转的时候选取的是向量，它的方向是确定的，不随坐标系的变化而变化，所以（4）仍然适用于我们的坐标系。</p>
<p>有了公式（4）,选取适当的旋转中心（x0,y0）就可以进行转换了。为了效率，我们可以把由四个小方块组成的大方块排除在外，不用旋转。</p>
<p><a href="http://pwwang.com/wp-content/uploads/tetris/tetris.rar" target="_blank">源代码下载</a></p>
<p>&nbsp;</p>
<p>Home Page in Google Code: <a href="http://code.google.com/p/tetris-in-jquery-javascript/" target="_blank">http://code.google.com/p/tetris-in-jquery-javascript/</a></p>
<h1>Introduction</h1>
<p>jQuery.msgbox game called tetris(俄罗斯方块) in jQuery/JavaScript<a href="/p/tetris-in-jquery-javascript/w/edit/JavaScript">?</a></p>
<h1>Information</h1>
<p>pwwang <a rel="nofollow" href="http://pwwang.com">http://pwwang.com</a></p>
<p>page <a rel="nofollow" href="http://pwwang.com/technology/js-javascript/tetris-in-jquery-%0A%0Ajavascript/">http://pwwang.com/technology/js-javascript/tetris-in-  jquery-javascript/</a></p>
<p>demo <a rel="nofollow" href="http://pwwang.com/tools/tetris.html">http://pwwang.com/tools/tetris.html</a></p>
<h1>Details</h1>
<ul>
<li>It&#8217;s a classic tetris</li>
<li>It has basic functions of tetris</li>
<li>You could decide to show the grids or not</li>
<li>You could choose to show the shadow( will the falling shape will   locate ) or  not</li>
<li>Pause or resume game</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/tetris-in-jquery-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jquery.msgbox is now hosting in Google Code</title>
		<link>http://pwwang.com/technology/js-javascript/jquery-msgbox-is-now-hosting-in-google-code/</link>
		<comments>http://pwwang.com/technology/js-javascript/jquery-msgbox-is-now-hosting-in-google-code/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 13:02:22 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[div提示框]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=735</guid>
		<description><![CDATA[&#160;

Introduction



<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/jquery-msgbox-is-now-hosting-in-google-code/" title="jquery.msgbox is now hosting in Google Code">Read More: 712 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<h1>Introduction</h1>
<p>
jQuery.msgbox Popups a msgbox on the web pages using jquery JavaScript Library</p>
<h1>Information</h1>
<p>
pwwang http://pwwang.com</p>
<p>plugin page http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/</p>
<h1>Details</h1>
<p>
It can:</p>
<ul>
<li>simulate window.alert, and the title of the box will flash if you try to click other part of the page</li>
<li>simulate window.confirm</li>
<li>allow you to popup a plain text box</li>
<li>allow you to popup a iframe in the box</li>
<li>allow you to popup a box with Ajax method</li>
<li>be closed automatically as you wish</li>
<li>mask the back contents of page when box showed</li>
<li>do an event you designated when the box closes</li>
<li>be dragged to anywhere in the window as you wish</li>
<li>decided whether popup another box if the page is in the iframe of a box</li>
</ul>
<p>&nbsp;<span style="color: #ff6600"><strong>Project Home Page:</strong></span> <a href="http://code.google.com/p/jquery-msgbox/">http://code.google.com/p/jquery-msgbox/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/jquery-msgbox-is-now-hosting-in-google-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DIV提示框：jquery.msgbox.3.1</title>
		<link>http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-1/</link>
		<comments>http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-1/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 14:24:25 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[div提示框]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=700</guid>
		<description><![CDATA[&#160;

jquery.msgbox 3.1&#160;&#160;&#160; 历史版本：&#160; 1.0&#160;&#160; 2.0&#160;&#160;3.0

3.1 更新：

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-1/" title="DIV提示框：jquery.msgbox.3.1">Read More: 146 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>jquery.msgbox 3.1&nbsp;&nbsp;&nbsp; 历史版本：&nbsp; <a target="_blank" href="http://pwwang.com/technology/js-javascript/%e5%8f%88%e8%a7%81div%e6%8f%90%e7%a4%ba%e6%a1%86jquery%e7%89%88/">1.0</a>&nbsp;&nbsp; <a target="_blank" href="http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/">2.0</a>&nbsp;&nbsp;<a target="_blank" href="http://pwwang.com/technology/js-javascript/div提示框：jquery-msgbox-3-0/">3.0</a></p>
<p><strong>3.1 更新：</strong></p>
<blockquote>
<p>1. 修正IE8以下&ldquo;无法得到 display 属性。 参数无效&rdquo;的bug</p>
<p>2. 关闭提示框后移动提示框的HTML代码</p>
</blockquote>
<p><strong>下载：</strong></p>
<p><a target="_blank" href="/wp-content/uploads/2009/10/jquery.msgbox.3.1/jquery.msgbox.js">jquery.msgbox.js</a></p>
<p><a target="_blank" href="/wp-content/uploads/2009/10/jquery.msgbox.3.1/jquery.msgbox.css">jquery.msgbox.css</a></p>
<p><a target="_blank" href="/wp-content/uploads/2009/10/jquery.msgbox.3.1/close.gif">close.gif</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DIV提示框：jquery.msgbox.3.0</title>
		<link>http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-0/</link>
		<comments>http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-0/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 02:55:14 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[div提示框]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-0/</guid>
		<description><![CDATA[&#160;

jquery.msgbox 3.0&#160;&#160;&#160; 历史版本：&#160; 1.0&#160;&#160; 2.0

测试页面

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-0/" title="DIV提示框：jquery.msgbox.3.0">Read More: 369 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>jquery.msgbox 3.0&nbsp;&nbsp;&nbsp; 历史版本：&nbsp; <a target="_blank" href="http://pwwang.com/technology/js-javascript/%e5%8f%88%e8%a7%81div%e6%8f%90%e7%a4%ba%e6%a1%86jquery%e7%89%88/">1.0</a>&nbsp;&nbsp; <a target="_blank" href="http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/">2.0</a></p>
<p><a target="_blank" href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.0/jquery.msgbox.3.0.test.htm"><span style="color: #ff0000"><strong><span style="font-size: medium">测试页面</span></strong></span></a></p>
<p><strong>3.0 更新：</strong></p>
<blockquote>
<p>1. 真正加入关闭后事件（上一版本忘了加）</p>
<p>2. 加入字符串调用模式，仅给出字符串参数就可以弹出提示框</p>
<p>3. 加入了定义标题的css，修正了titleClass不能定义标题的bug</p>
<p>4. 加入针对iframe的oneBoxMode，控制在iframe中是否能再弹出提示框</p>
<p>5. 加入单击背景层标题栏闪动的功能（类似alert）</p>
<p>6. 自动计算以定位关闭图标的位置</p>
<p>7. 自动计算iframe的高度</p>
<p>8. 修正页面较窗口短时背景层不能盖住整个页面的bug，并修正背景层过长的bug</p>
<p>9. 修正iframe模式下，拖拽提示框鼠标进入iframe后拖拽不结束的bug</p>
</blockquote>
<p><strong><span id="more-683"></span></strong></p>
<p><strong>3.0后版本不贴出源代码，请大家下载后自行浏览。</strong></p>
<p><strong>下载：</strong></p>
<p><a target="_blank" href="/wp-content/uploads/2009/10/jquery.msgbox.3.0/jquery.msgbox.js">jquery.msgbox.js</a></p>
<p><a target="_blank" href="/wp-content/uploads/2009/10/jquery.msgbox.3.0/jquery.msgbox.css">jquery.msgbox.css</a></p>
<p><a target="_blank" href="/wp-content/uploads/2009/10/jquery.msgbox.3.0/close.gif">close.gif</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/div%e6%8f%90%e7%a4%ba%e6%a1%86%ef%bc%9ajquery-msgbox-3-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery插件：DIV提示框jquery.msgbox</title>
		<link>http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/</link>
		<comments>http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 16:20:21 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Js/AJAX]]></category>
		<category><![CDATA[div提示框]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=678</guid>
		<description><![CDATA[&#160;

此插件所有的更新都会跟在此文章后, 特此通知!

Google Code Project Home Page: http://code.google.com/p/jquery-msgbox/

<span class="readmore"><a href="http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/" title="jQuery插件：DIV提示框jquery.msgbox">Read More: 2279 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><span style="color: rgb(255, 0, 0);"><strong><span style="font-size: small;">此插件所有的更新都会跟在此文章后, 特此通知!</span></strong></span></p>
<p><span style="color: rgb(255, 102, 0);"><strong>Google Code Project Home Page:</strong></span> <a href="http://code.google.com/p/jquery-msgbox/">http://code.google.com/p/jquery-msgbox/</a></p>
<p>原1.0版本查看：<a href="../../../../../technology/js-javascript/%e5%8f%88%e8%a7%81div%e6%8f%90%e7%a4%ba%e6%a1%86jquery%e7%89%88/" rel="bookmark">又见div提示框,jQuery版</a></p>
<p><strong>2.0版本改进：</strong></p>
<blockquote>
<p>1. 修改了插件的整个写法，可读性更好，将直接的HTML操作改为jquery对象的操作，出错可能性减小</p>
<p>2. 自动关闭时间初始值由-1改为0, 逻辑更可取</p>
<p>3. 分离了各部分样式（除了显示必须的样式）</p>
<p>4. 关闭时的事件，由原有的eval实现，改为直接函数传递，操作性更强</p>
<p>5. 加入了关闭图标，更美观</p>
<p>6. 背景透明值可设定（0~1）</p>
<p>7. 加入了ajax方式完成后的事件，且参数data可以传递</p>
<p>8. 解决了原版拖拽时鼠标容易脱离的问题，使得拖拽更加连贯</p>
<p>9. 解决了IE中背景层无法盖住select的bug</p>
<p>10. 解决了拖拽时提示框可以拖出界外的bug</p>
<p>11. 将原有的click关闭提示框的方式改为mousedown，防止关闭按钮上的拖拽</p>
<p>12. 解决了手动关闭提示框后，自动关闭数秒仍然运行的bug</p>
<p>13. 加入改变窗口大小重置提示框位置的功能</p>
</blockquote>
<p>&nbsp;</p>
<p><span id="more-678"></span></p>
<p><strong>下载：</strong></p>
<p><a href="/wp-content/uploads/2009/09/jquery.msgbox.js" target="_blank">jquery.msgbox.js</a></p>
<p><a href="/wp-content/uploads/2009/09/jquery.msgbox.css" target="_blank">jquery.msgbox.css</a></p>
<p><a href="/wp-content/uploads/2009/09/close.gif" target="_blank">close.gif <img border="0" src="/wp-content/uploads/2009/09/close.gif" alt="" /></a></p>
<hr />
<p><strong>3.0 更新：&nbsp;&nbsp;&nbsp;<a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.0/jquery.msgbox.3.0.test.htm" target="_blank"><span style="font-size: medium;"><span style="color: rgb(255, 0, 0);"><strong>测试页面</strong></span></span></a></strong></p>
<blockquote>
<p>1. 真正加入关闭后事件（上一版本忘了加）</p>
<p>2. 加入字符串调用模式，仅给出字符串参数就可以弹出提示框</p>
<p>3. 加入了定义标题的css，修正了titleClass不能定义标题的bug</p>
<p>4. 加入针对iframe的oneBoxMode，控制在iframe中是否能再弹出提示框</p>
<p>5. 加入单击背景层标题栏闪动的功能（类似alert）</p>
<p>6. 自动计算以定位关闭图标的位置</p>
<p>7. 自动计算iframe的高度</p>
<p>8. 修正页面较窗口短时背景层不能盖住整个页面的bug，并修正背景层过长的bug</p>
<p>9. 修正iframe模式下，拖拽提示框鼠标进入iframe后拖拽不结束的bug</p>
</blockquote>
<p><strong>下载：</strong></p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.0/jquery.msgbox.js" target="_blank"><font color="#432d00">jquery.msgbox.js</font></a></p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.0/jquery.msgbox.css" target="_blank"><font color="#432d00">jquery.msgbox.css</font></a></p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.0/close.gif" target="_blank"><font color="#432d00">close.gif</font></a></p>
<hr />
<p><strong>3.1 更新：</strong></p>
<blockquote>
<p>1. 修正IE8以下&ldquo;无法得到 display 属性。 参数无效&rdquo;的bug</p>
<p>2. 关闭提示框后移动提示框的HTML代码</p>
</blockquote>
<p><strong>下载：</strong></p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.1/jquery.msgbox.js" target="_blank">jquery.msgbox.js</a></p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.1/jquery.msgbox.css" target="_blank">jquery.msgbox.css</a></p>
<p><a href="http://pwwang.com/wp-content/uploads/2009/10/jquery.msgbox.3.1/close.gif" target="_blank">close.gif</a></p>
<hr />
<p><strong>4.0更新:&nbsp;&nbsp;&nbsp;<a href="http://pwwang.com/wp-content/uploads/jquery.msgbox/test.html" target="_blank"><span style="font-size: large;"><span style="color: rgb(255, 0, 0);"><strong>测试页面</strong></span></span></a></strong></p>
<blockquote>
<p>1. 彻底修正ie6中无法得到display属性的问题和找不到关闭图标的问题</p>
<p>2. 增加firefox有效的弹出对话框时隐藏滚动条的功能（IE下无效）</p>
<p>3. 增加alert模式，模拟window.alert的效果</p>
<p>4. 增加confirm模式，模拟window.confirm效果，并可得到返回值</p>
<p>5. 修正oneBoxMode，只针对iframe中再弹出iframe的情况</p>
<p>6. 对代码进行了其他调整</p>
<p>7. 提供jquery.msgbox.min.js的下载，代码更简化，调用效率更高</p>
</blockquote>
<p><strong>下载：</strong></p>
<p><a href="/wp-content/uploads/jquery.msgbox/4.0/jquery.msgbox.rar" target="_blank">jquery.msgbox.rar</a></p>
<p>&nbsp;</p>
<hr />
<p><span style="font-size: medium;"><strong>jquery.msgbox.4.1</strong></span><strong>&nbsp; </strong><strong><strong><a href="http://pwwang.com/wp-content/uploads/jquery.msgbox/test.html" target="_blank"><span style="font-size: large;"><span style="color: rgb(255, 0, 0);"><strong>Demo</strong></span></span></a></strong></strong></p>
<p><strong>更新:&nbsp;&nbsp;&nbsp;</strong></p>
<blockquote>
<p>1. 关闭图标载入之前是加入&ldquo;关闭&rdquo;字样</p>
<p>2. 修正页面过长或过宽时提示框仍在左上的bug（感谢<span id="commentauthor-444"> hxhui08 的提醒</span>）</p>
</blockquote>
<p><strong>下载：</strong></p>
<p><a href="/wp-content/uploads/jquery.msgbox/4.1/jquery.msgbox.4.1.rar" target="_blank">jquery.msgbox.4.1.rar</a></p>
<hr />
<p><span style="font-size: medium;"><strong>jquery.msgbox.4.2</strong></span><strong>&nbsp; </strong><strong><strong><a href="http://pwwang.com/wp-content/uploads/jquery.msgbox/test.html" target="_blank"><span style="font-size: large;"><span style="color: rgb(255, 0, 0);"><strong>Demo</strong></span></span></a></strong></strong></p>
<p><strong>更新:&nbsp;&nbsp;&nbsp;</strong></p>
<blockquote>
<p>1. 修正IE6下背景层无法盖住select的bug(感谢yygcom)</p>
</blockquote>
<p><strong>下载：</strong></p>
<p><a href="/wp-content/uploads/jquery.msgbox/4.2/jquery.msgbox.4.2.zip" target="_blank">jquery.msgbox.4.2.zip</a></p>
<hr />
<p><span style="font-size: medium;"><strong>jquery.msgbox.5.0</strong></span><strong>&nbsp; </strong><strong><strong><a target="_blank" href="http://pwwang.com/wp-content/uploads/jquery.msgbox/test.html"><span style="font-size: large;"><span style="color: rgb(255, 0, 0);"><strong>Demo</strong></span></span></a></strong></strong></p>
<p>&nbsp;</p>
<p><strong>更新:&nbsp;&nbsp;&nbsp;</strong></p>
<p>&nbsp;</p>
<blockquote>
<p>1. 更改了一些设置的参数名称: 如closeAfter =&gt; autoClose, closeEvent =&gt; onClose, 意思更加明确</p>
<p>2. 增加了对input的支持, 并支持自定义input box的class, 采用onInputed函数来返回输入的值</p>
<p>3. 增加了是否允许拖拽的设置参数: enableDrag</p>
<p>4. 增加了提示框打开和关闭时是否允许动画的设置参数</p>
<p>5. 页面滚动时, 使得提示框相对窗口的位置不动</p>
<p>6. 增加了从外部关闭提示框的方法 $.closemsgbox, 具体设置参见demo中的说明</p>
<p>7. 不再强行需要关闭图标,当不设置closeImg时,显示&quot;关闭&quot;字样</p>
<p>8. 去掉了oneboxmode及hidescrollbar等一些鸡肋属性设置, 去掉了处理select的遮盖问题的方法</p>
<p>9. 更改了拖拽函数, 使用jquery.dragndrop插件, 对dragndrop进行了一些修正(请使用我提供的这个插件)</p>
<p>10. 针对text或ajax, 内容框的overflow默认方法不再是hidden, 更改为auto.</p>
</blockquote>
<p>&nbsp;</p>
<p><strong>下载：</strong></p>
<p>&nbsp;</p>
<p><a target="_blank" href="/wp-content/uploads/jquery.msgbox/5.0/jquery.msgbox.5.0.rar">jquery.msgbox.5.0.rar</a></p>
<hr />
<p><span style="font-size: medium;"><strong>jquery.msgbox.6.0</strong></span><strong>&nbsp; </strong><strong><strong><a href="http://pwwang.com/wp-content/uploads/jquery.msgbox/6.0/demo.htm" target="_blank"><span style="font-size: large;"><span style="color: rgb(255, 0, 0);"><strong>Demo</strong></span></span></a></strong></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date ： 2010.5.12</p>
<p><strong>更新:&nbsp;&nbsp;&nbsp;</strong></p>
<blockquote>
<p>1. 更改整个插件的编码框架，有利于从外部操作msgbox</p>
<p>2. 增加多种外部操作方法（例如从外部关闭msgbox）</p>
<p>3. type参数不再独立，合并到content中</p>
<p>4. closeImg更改为closeIcon，结构为&#8217;close&#8217; 或 {type:&#8217;icon&#8217;, content: &#8216;close.gif&#8217;} 或{type:&#8217;string&#8217;, content: &#8216;close&#8217;}</p>
<p>5. msgbox的返回值可以直接从外部方式$mb.value得到，其中$mb是msgbox的handle（$mb=$.msgbox(&#8230;)）</p>
<p>6. 可以通过参数animation指定不同的动画效果</p>
<p>7. 提供<a target="_blank" href="http://pwwang.com/wp-content/uploads/jquery.msgbox/6.0/README.txt">README</a>和<a target="_blank" href="http://pwwang.com/wp-content/uploads/jquery.msgbox/6.0/CHANGELOG.txt">CHANGELOG</a>文件，介绍插件详细使用方法</p>
<p>8. 修改其他小bug
</p></blockquote>
<p><strong>下载：</strong></p>
<p><a href="/wp-content/uploads/jquery.msgbox/6.0/jquery.msgbox.6.0.rar" target="_blank">jquery.msgbox.6.0.rar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/technology/js-javascript/jquery%e6%8f%92%e4%bb%b6%ef%bc%9adiv%e6%8f%90%e7%a4%ba%e6%a1%86jquery-msgbox-2-0/feed/</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
	</channel>
</rss>
