<?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; 字符串</title>
	<atom:link href="http://www.uideas.cn/post/tag/%e5%ad%97%e7%ac%a6%e4%b8%b2/feed" rel="self" type="application/rss+xml" />
	<link>http://www.uideas.cn</link>
	<description>生活来源于创意,所以我懂生活</description>
	<lastBuildDate>Sun, 22 Aug 2010 07:17:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>js拼接字符串</title>
		<link>http://www.uideas.cn/post/107.html</link>
		<comments>http://www.uideas.cn/post/107.html#comments</comments>
		<pubDate>Thu, 22 Oct 2009 14:05:02 +0000</pubDate>
		<dc:creator>kos</dc:creator>
				<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[join()]]></category>
		<category><![CDATA[options]]></category>
		<category><![CDATA[selectedIndex]]></category>
		<category><![CDATA[字符串]]></category>
		<category><![CDATA[拼接]]></category>

		<guid isPermaLink="false">http://uideas.cn/?p=107</guid>
		<description><![CDATA[　　今天做了一个有点意思的字符串拼接，后来发现很多地方都有用。比如：注册的时候选择出生地，籍贯等等相似的地方都可以用到。以下例子涉及到两点：1、join()方法；先定义一个数组，把要拼接的两个变量放到数组里面，然后再用join方法把拼接在一起。]]></description>
			<content:encoded><![CDATA[<p>　　今天做了一个有点意思的字符串拼接，后来发现很多地方都有用，比如：注册的时候选择出生地，籍贯等等相似的地方都可以用到。以下例子涉及到两点：</p>
<p>1、join()方法<br />
先定义一个数组，把要拼接的两个变量放到数组里面，然后再用join方法把拼接在一起。<br />
例1：<br />
<code><br />
var arr = new Array("张三","是","我","小弟");<br />
var content = arr.join("");<br />
alert(content);<br />
此时打印的结果是“张三是我弟弟”<br />
例2：<br />
var arr = new Array("2009","10","22");<br />
var date= arr.join("-");<br />
alert(content);<br />
此时打印的结果是“2009-10-22”。<br />
</code></p>
<p>2、js获取下拉菜单中被选中的值，通过selectedIndex得到选中的元素，把放到一个options数组里面,然后得到它的文字或者value值。<br />
例如：<br />
<code><br />
var select = document.getElementById("select");<br />
var selected = select.options[select.selectedIndex].text;//获得select下拉菜单被选中的文字<br />
var selected = select.options[select.selectedIndex].value;//获得select下拉菜单被选中的value值<br />
</code></p>
<p>这样说来好象体现不了实用性，下面是完整的一个例子：</p>
<form enctype="application/x-www-form-urlencoded"><code></p>
<div class="Nodiv">
<div class="Notitle">CODE</div>
<div class="Nocontent"><textarea class="textarea" cols="20" rows="8">&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;title&gt;无标题文档&lt;/title&gt; &lt;script type="text/javascript"&gt; function joinselect(){ var select1 = document.getElementById("select1"); var select2 = document.getElementById("select2"); var text1 = document.getElementById("text1"); var qqq = new Array(select1.options[select1.selectedIndex].text,select2.options[select2.selectedIndex].text); text1.value = qqq.join("");  }&lt;/script&gt; &lt;/head&gt;  &lt;body&gt; 省：   &lt;select name="select" id="select1"&gt;     &lt;option value="1" selected&gt;四川&lt;/option&gt;     &lt;option value="2"&gt;贵州&lt;/option&gt;     &lt;option&gt;云南&lt;/option&gt;   &lt;/select&gt; 市： &lt;select name="select2" id="select2"&gt;   &lt;option value="1"&gt;成都&lt;/option&gt;   &lt;option value="2"&gt;达州&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;input type="button" onClick="joinselect()" value="拼在一起"&gt; &lt;br&gt; &lt;input type="text" name="textfield" id="text1"&gt; &lt;/body&gt; &lt;/html&gt; </textarea></div>
<div class="Nobutton">
<input onclick="RunCode(this)" type="button" value="运行代码" />
<input onclick="CopyCode(this)" type="button" value="复制代码" />
<input onclick="SaveCode(this)" type="button" value="保存代码" />
<span class="Nots">[Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</span>
</div>
</div>
<p></code></form>
]]></content:encoded>
			<wfw:commentRss>http://www.uideas.cn/post/107.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
