<?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; jquery</title>
	<atom:link href="http://www.havenliu.com/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://www.havenliu.com</link>
	<description>记录点生活的无奈</description>
	<lastBuildDate>Thu, 29 Dec 2011 03:25:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Jquery html(val)使用注意</title>
		<link>http://www.havenliu.com/web/446.html</link>
		<comments>http://www.havenliu.com/web/446.html#comments</comments>
		<pubDate>Thu, 27 May 2010 05:46:16 +0000</pubDate>
		<dc:creator>Haven</dc:creator>
				<category><![CDATA[Web开发]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.havenliu.com/?p=446</guid>
		<description><![CDATA[Jquery的html(val)可以方面的向页面元素内部插入html代码，但要注意插入的html代码中不能包含script代码块，如果包含&#60;script&#62;&#8230;.&#60;/script&#62;这样的代码jquery会在插入的时候自动过滤掉，遇到这样的问题最好的方法还是用document.getElementById(&#8221;div&#8221;).innerHTML=html最保险。
相关文章2009年09月20日 -- JQuery基础入门-输入验证]]></description>
			<content:encoded><![CDATA[<p>Jquery的html(val)可以方面的向页面元素内部插入html代码，但要注意插入的html代码中不能包含script代码块，如果包含&lt;script&gt;&#8230;.&lt;/script&gt;这样的代码jquery会在插入的时候自动过滤掉，遇到这样的问题最好的方法还是用document.getElementById(&#8221;div&#8221;).innerHTML=html最保险。</p>
<div style="float:left;margin:0px 0px 0px 0px;"><a title="Post on Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" data-url="http://www.havenliu.com/web/446.html"></a><script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script></div><h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年09月20日 -- <a href="http://www.havenliu.com/web/238.html" title="JQuery基础入门-输入验证">JQuery基础入门-输入验证</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.havenliu.com/web/446.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQuery基础入门-输入验证</title>
		<link>http://www.havenliu.com/web/238.html</link>
		<comments>http://www.havenliu.com/web/238.html#comments</comments>
		<pubDate>Mon, 21 Sep 2009 03:27:29 +0000</pubDate>
		<dc:creator>Haven</dc:creator>
				<category><![CDATA[Web开发]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.havenliu.com/?p=238</guid>
		<description><![CDATA[以前对JQuery一直保持观望态度，没太深入研究。最近一个项目，到现在第一阶段算是快完成了，发现和同事的javascript代码功能重复的很多，重用性也不好，冗余代码也很多，才想到了转用JQuery开发框架。找了点资料来看了下，发现JQuery相当强大，真是相见恨晚啦！
这篇教程是最基础的JQuery入门教程。为了刚接触JQuery的人能看懂，代码写的比较繁琐，主要是为了写注释方便，如果看了还有不懂的可以联系我，大家共同探讨.

代码点击可以直接下载看效果，注意js文件结构，js文件（包括jquery.js）要放在js文件夹下面，jquery.js大家可以到Jquery的官网去下载：jquery.com
html文件：

?Download verify.html&#60;!DOCTYPE HTML PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34;&#62;
&#60;html&#62;
  &#60;head&#62;
    &#60;title&#62;输入验证&#60;/title&#62;
    &#60;meta http-equiv=&#34;keywords&#34; content=&#34;keyword1,keyword2,keyword3&#34;&#62;
    &#60;meta http-equiv=&#34;description&#34; content=&#34;this is my page&#34;&#62;
    &#60;meta http-equiv=&#34;content-type&#34; content=&#34;text/html; charset=UTF-8&#34;&#62;
    &#60;script src=&#34;js/jquery.js&#34; type=&#34;text/javascript&#34; &#62;&#60;/script&#62;
    &#60;script src=&#34;js/verify.js&#34; type=&#34;text/javascript&#34; &#62;&#60;/script&#62;
&#160;
&#160;
    &#60;style type=&#34;text/css&#34;&#62;
&#60;!--
.warning{
	border:1px [...]]]></description>
			<content:encoded><![CDATA[<p>以前对JQuery一直保持观望态度，没太深入研究。最近一个项目，到现在第一阶段算是快完成了，发现和同事的javascript代码功能重复的很多，重用性也不好，冗余代码也很多，才想到了转用JQuery开发框架。找了点资料来看了下，发现JQuery相当强大，真是相见恨晚啦！</p>
<p>这篇教程是最基础的JQuery入门教程。为了刚接触JQuery的人能看懂，代码写的比较繁琐，主要是为了写注释方便，如果看了还有不懂的可以联系我，大家共同探讨.<br />
<span id="more-238"></span><br />
代码点击可以直接下载看效果，注意js文件结构，js文件（包括jquery.js）要放在js文件夹下面，jquery.js大家可以到Jquery的官网去下载：<a href="jquery.com">jquery.com</a></p>
<p>html文件：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.havenliu.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=238&amp;download=verify.html">verify.html</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2383"><td class="code" id="p238code3"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;输入验证&lt;/title&gt;
    &lt;meta http-equiv=&quot;keywords&quot; content=&quot;keyword1,keyword2,keyword3&quot;&gt;
    &lt;meta http-equiv=&quot;description&quot; content=&quot;this is my page&quot;&gt;
    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
    &lt;script src=&quot;js/jquery.js&quot; type=&quot;text/javascript&quot; &gt;&lt;/script&gt;
    &lt;script src=&quot;js/verify.js&quot; type=&quot;text/javascript&quot; &gt;&lt;/script&gt;
&nbsp;
&nbsp;
    &lt;style type=&quot;text/css&quot;&gt;
&lt;!--
.warning{
	border:1px  solid red;
}
--&gt;
    &lt;/style&gt;
  &lt;/head&gt;
&nbsp;
  &lt;body&gt;
    请输入用户名：
    &lt;input type=&quot;text&quot; name=&quot;userName&quot; id=&quot;userName&quot; &gt;&lt;input id=&quot;verify&quot; type=&quot;button&quot; value=&quot;verify&quot;&gt;
    &lt;div id=&quot;show&quot;&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>js文件：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.havenliu.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=238&amp;download=verify.js">verify.js</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2384"><td class="code" id="p238code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//初始化，$(document).ready()表示页面加载完成后执行</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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;
&nbsp;
	<span style="color: #006600; font-style: italic;">//找到页面上id为verify的按钮。并为它添加点击事件,click为jquery的点击事件</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#verify&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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: #006600; font-style: italic;">//当按钮点击的时候执行下面的代码</span>
		<span style="color: #006600; font-style: italic;">//找到页面上id为userName的文本框，并获取文本框内的值，用jquery提供的val方法</span>
		<span style="color: #003366; font-weight: bold;">var</span> userName<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#userName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//判断userName的值是不是为空</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>userName<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//如果为空，提示用户</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#show&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;用户名不能为空&quot;</span><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>
			<span style="color: #006600; font-style: italic;">//如果不为空，则将userName的值发送给服务器端，校验是否重复等，这里简化操作，直接判断如果userName的值为admin，则提示用户名重复</span>
		<span style="color: #006600; font-style: italic;">/**	
			//如果使用服务器端来校验userName，使用juery提供的get方法，get方法的有三个参数，第一个是服务器端的url，
			// 第二个是发送给服务器端的数据，这里我的数据直接在前面的url中已经传递过去，所以为null，
			// 第三个参数是一个function，它表示服务器端校验完成，返回后需要调用的函数
			$.get(&quot;verify.action?userName=&quot;+userName,null,function(response){
				//将服务器端返回的值显示在div中
				$(&quot;#show&quot;).html(response);
			});
			*/</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>userName<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#show&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;用户名已经存在&quot;</span><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>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#show&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;恭喜您，该用户名可以注册&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//找到页面上id为userName的输入框，并为它添加键盘出发事件，keyup为jquery的键盘触发事件，表示键盘上某个键被按下后弹起来后触发</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#userName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</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: #006600; font-style: italic;">//找到页面上id为userName的文本框，并获取文本框内的值，用jquery提供的val方法</span>
		<span style="color: #003366; font-weight: bold;">var</span> userName<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#userName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//如果userName的值内空，则文本框显示红色</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>userName<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//addClass是JQuery提供的方法，表示给某个页面控件添加一个class</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;warning&quot;</span><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>
			<span style="color: #006600; font-style: italic;">//removeClass是JQuery提供的方法，表示给某个页面控件删除class</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;warning&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<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: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<div style="float:left;margin:0px 0px 0px 0px;"><a title="Post on Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-count" data-url="http://www.havenliu.com/web/238.html"></a><script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script></div><h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年05月27日 -- <a href="http://www.havenliu.com/web/446.html" title="Jquery html(val)使用注意">Jquery html(val)使用注意</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.havenliu.com/web/238.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

