<?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; Dom</title>
	<atom:link href="http://swayweb.com/tag/dom/feed" rel="self" type="application/rss+xml" />
	<link>http://swayweb.com</link>
	<description>Sway的官方博客</description>
	<lastBuildDate>Mon, 19 Jul 2010 12:54:08 +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>对input 使用focus()函数(兼容Firefox和IE)</title>
		<link>http://swayweb.com/tech/1372</link>
		<comments>http://swayweb.com/tech/1372#comments</comments>
		<pubDate>Sun, 29 Nov 2009 13:35:26 +0000</pubDate>
		<dc:creator>Sway</dc:creator>
				<category><![CDATA[老技术]]></category>
		<category><![CDATA[Dom]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://swayweb.com/?p=1372</guid>
		<description><![CDATA[我们有时会有这样的需求：当页面加载完成后自动将光标定位到某个输入框上，起到引导和方便用户之功效，如谷歌首页、Gmail登陆界面等；原理较简单，通常可以用一段Javascript略微控制，如 ... window.onload = function(){ document.getElementById('term').focus(); //假设页面中需要赋予焦点的input的id为'term'; } ... 以上代码可以解决input框初始值为空的情况，假如初始值不为空，如我们引导用户输入一个网址，使初始值为&#8217;http://&#8217;，这时HTML可能是这样: ... ... 如果再试图用上面的Javascript代码来赋予焦点，会发现在Firefox下光标停在input框内文字的末尾，而在IE6下却停在了input框内文字的开头处，通常，Firefox的执行结果使我们所希望的。要想让IE6得到像Firefox一样的结果，以下是我的解决办法： ... window.onload = function(){ var term = document.getElementById('term'); term.focus(); term.value = term.value; //关键就是多加了这一句; } ...]]></description>
			<content:encoded><![CDATA[<p>我们有时会有这样的需求：当页面加载完成后自动将光标定位到某个输入框上，起到引导和方便用户之功效，如谷歌首页、Gmail登陆界面等；原理较简单，通常可以用一段Javascript略微控制，如</p>
<pre name="code" class="html">...
window.onload = function(){
   document.getElementById('term').focus(); //假设页面中需要赋予焦点的input的id为'term';
 }
...</pre>
<p>以上代码可以解决input框初始值为空的情况，假如初始值不为空，如我们引导用户输入一个网址，使初始值为&#8217;http://&#8217;，这时HTML可能是这样:</p>
<pre name="code" class="html">...
<input id="term" type="text" value="http://"  />
...</pre>
<p>如果再试图用上面的Javascript代码来赋予焦点，会发现在Firefox下光标停在input框内文字的末尾，而在IE6下却停在了input框内文字的开头处，通常，Firefox的执行结果使我们所希望的。要想让IE6得到像Firefox一样的结果，以下是我的解决办法：</p>
<pre name="code" class="html">...
   window.onload = function(){
     var term = document.getElementById('term');
     term.focus();
     term.value = term.value;     //关键就是多加了这一句;
   }
...</pre>
]]></content:encoded>
			<wfw:commentRss>http://swayweb.com/tech/1372/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
