<?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>超群.com的博客 &#187; checkbox</title>
	<atom:link href="http://www.fuchaoqun.com/tag/checkbox/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fuchaoqun.com</link>
	<description></description>
	<lastBuildDate>Thu, 08 Sep 2011 15:08:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>翻页保持checkbox勾选状态的实现</title>
		<link>http://www.fuchaoqun.com/2008/08/pager_with_checkbox_on/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pager_with_checkbox_on</link>
		<comments>http://www.fuchaoqun.com/2008/08/pager_with_checkbox_on/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 09:18:38 +0000</pubDate>
		<dc:creator>超群.com</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[mootools]]></category>
		<guid isPermaLink="false">http://chaoqun.17348.com/?p=47</guid>
		<description><![CDATA[本博客所有原创文章采用知识共享署名-非商业性使用-相同方式共享，转载请保留链接http://chaoqun.17348.com/2008/08/pager_with_checkbox_on/ 之前的一个项目，给新浪空间做的音乐控件，大家可以登录上去看一下，个人感觉产品设计不错，我现在天天就在上面在线听音乐，大家可以测试一下里面的搜索效果，在搜索结果的第一页选择一些歌曲(或者全选)，然后翻任意页，再选，再翻任意页，再选，后头查一下你选择过了的页面，看看是不是你之前选择过的歌曲还保留着，下面就说一下这个的实现方式，javascript部分居于mootools。 实现原理： 每一个分页都包含在一个id为page+页码的div中，翻到其他页时，隐藏当前页，首先判断目标页是否已经加载过，如果没有就通过ajax去获取页面，同样包含在一个page+页面的div中，等于说所有的分页都在页面中，只不过非当前页的div都设为display=none了，所以细心的你可能会发现加载过的页面再加载怎么会那么快啊。 核心的部分就是这个javascript函数： // 显示分页，传进去分页页码 function show_search_page&#40;page_num&#41; &#123; // 首先判断目标页是否已经加载过，加载过的话就把其他页都设定隐藏再把当前页显示，然后结束返回        if &#40;$chk&#40;$&#40;'page'+page_num&#41;&#41;&#41;     &#123;         $&#40;'song_div'&#41;.getElements&#40;'div[id^=page]'&#41;.each&#40;function&#40;item,index&#41;&#123;$&#40;item&#41;.setStyle&#40;'display','none'&#41;;&#125;&#41;;         $&#40;'page'+page_num&#41;.setStyle&#40;'display','block'&#41;;         return;     &#125; &#160; // 如果没有加载过，就通过ajax去获取页面数据，然后生成一个page+页面的div，并显示出来     var search_song_with_ajax = new Ajax&#40;'./getsearchdata.php?cur_page=' + page_num + '&#38;amp;key={_$search_key_}',     &#123;method: 'get',     onComplete: function&#40;&#41;&#123;         $&#40;'song_div'&#41;.getElements&#40;'div[id^=page]'&#41;.each&#40;function&#40;item,index&#41;&#123;$&#40;item&#41;.setStyle&#40;'display','none'&#41;;&#125;&#41;;         var new_div = new Element&#40;'div',&#123;             'id':'page'+page_num         [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>本博客所有原创文章采用<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank">知识共享署名-非商业性使用-相同方式共享</a>，转载请保留链接<a href="http://chaoqun.17348.com/2008/08/pager_with_checkbox_on/">http://chaoqun.17348.com/2008/08/pager_with_checkbox_on/</a></p></blockquote>
<p>之前的一个项目，给<a href="http://space.sina.com.cn/" target="_blank">新浪空间</a>做的音乐控件，大家可以登录上去看一下，个人感觉产品设计不错，我现在天天就在上面在线听音乐，大家可以测试一下里面的搜索效果，在搜索结果的第一页选择一些歌曲(或者全选)，然后翻任意页，再选，再翻任意页，再选，后头查一下你选择过了的页面，看看是不是你之前选择过的歌曲还保留着，下面就说一下这个的实现方式，javascript部分居于mootools。</p>
<p>实现原理：</p>
<p>每一个分页都包含在一个id为page+页码的div中，翻到其他页时，隐藏当前页，首先判断目标页是否已经加载过，如果没有就通过ajax去获取页面，同样包含在一个page+页面的div中，等于说所有的分页都在页面中，只不过非当前页的div都设为display=none了，所以细心的你可能会发现加载过的页面再加载怎么会那么快啊。</p>
<p>核心的部分就是这个javascript函数：</p>
<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// 显示分页，传进去分页页码</span>
<span style="color: #003366; font-weight: bold;">function</span> show_search_page<span style="color: #009900;">&#40;</span>page_num<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// 首先判断目标页是否已经加载过，加载过的话就把其他页都设定隐藏再把当前页显示，然后结束返回   </span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$chk<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'page'</span><span style="color: #339933;">+</span>page_num<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'song_div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElements</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[id^=page]'</span><span style="color: #009900;">&#41;</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: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'none'</span><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: #009900;">&#40;</span><span style="color: #3366CC;">'page'</span><span style="color: #339933;">+</span>page_num<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// 如果没有加载过，就通过ajax去获取页面数据，然后生成一个page+页面的div，并显示出来</span>
    <span style="color: #003366; font-weight: bold;">var</span> search_song_with_ajax <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./getsearchdata.php?cur_page='</span> <span style="color: #339933;">+</span> page_num <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;amp;key={_$search_key_}'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
    onComplete<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: #009900;">&#40;</span><span style="color: #3366CC;">'song_div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElements</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[id^=page]'</span><span style="color: #009900;">&#41;</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: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span>index<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'none'</span><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: #003366; font-weight: bold;">var</span> new_div <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">'id'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'page'</span><span style="color: #339933;">+</span>page_num
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span>new_div<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setHTML</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span>new_div<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">injectInside</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'song_div'</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: #009900;">&#41;</span>.<span style="color: #660066;">request</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>javascript的代码可以到页面去查看，hope it usefull for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fuchaoqun.com/2008/08/pager_with_checkbox_on/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
