<?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>Web notes &#187; select</title>
	<atom:link href="http://www.webnotes.com.ua/index.php/archives/tag/select/feed" rel="self" type="application/rss+xml" />
	<link>http://www.webnotes.com.ua</link>
	<description>nice web notes - полезные веб заметки</description>
	<lastBuildDate>Fri, 10 Sep 2010 06:36:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>jQuery работа с select</title>
		<link>http://www.webnotes.com.ua/index.php/archives/699</link>
		<comments>http://www.webnotes.com.ua/index.php/archives/699#comments</comments>
		<pubDate>Sun, 27 Sep 2009 10:36:19 +0000</pubDate>
		<dc:creator>nice</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Заметки]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://www.webnotes.com.ua/?p=699</guid>
		<description><![CDATA[Очень часто приходится сталкиваться с выпадающим HTML списком &#60;select&#62;, по этому на заметку оставлю несколько селекторов jQuery. Например, у нас имеется простенький &#60;select id=”my_select” name=”my_select”&#62; с id=”my_select” &#60;select id=&#34;my_select&#34; name=&#34;my_select&#34;&#62; &#60;option value=&#34;1&#34;&#62;one&#60;/option&#62; &#60;option value=&#34;2&#34;&#62;two&#60;/option&#62; &#60;option value=&#34;3&#34;&#62;three&#60;/option&#62; &#60;/select&#62; 1) Самое простое – получить значение выбранного элемента $(&#34;#my_select option:selected&#34;).val(); сокращенно: $(&#34;#my_select :selected&#34;).val(); или: $(&#34;select#my_select&#34;).val(); 2) Получаем текст [...]]]></description>
			<content:encoded><![CDATA[<p>Очень часто приходится сталкиваться с выпадающим HTML списком <span style="color: #888888;">&lt;select&gt;</span>, по этому на заметку оставлю несколько селекторов jQuery.</p>
<p><span id="more-699"></span></p>
<p>Например, у нас имеется простенький <strong><span style="color: #888888;">&lt;select id=”my_select” name=”my_select”&gt;</span></strong> с id=”my_select”</p>
<pre class="brush: html">&lt;select id=&quot;my_select&quot; name=&quot;my_select&quot;&gt;

&lt;option value=&quot;1&quot;&gt;one&lt;/option&gt;

&lt;option value=&quot;2&quot;&gt;two&lt;/option&gt;

&lt;option value=&quot;3&quot;&gt;three&lt;/option&gt;

&lt;/select&gt;</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>1) </strong>Самое простое – получить значение выбранного элемента</span></p>
<pre class="brush: js">$(&quot;#my_select option:selected&quot;).val();
сокращенно:
$(&quot;#my_select :selected&quot;).val();
или:
$(&quot;select#my_select&quot;).val();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>2)</strong> Получаем текст того же выбранного элемента</span></p>
<pre class="brush: js">$(&quot;#my_select :selected&quot;).html();
или:
$(&quot;#my_select :selected&quot;).text();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>3)</strong> Сделать &lt;select&gt; недоступным</span></p>
<pre class="brush: js">$(&quot;#my_select&quot;).attr(&quot;disabled&quot;,&quot;disabled&quot;);</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>4)</strong> Разблокировать &lt;select&gt;</span></p>
<pre class="brush: js">$(&quot;#my_select&quot;).attr(&quot;disabled&quot;,&quot;&quot;);</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>5)</strong> Удалить выбранный элемент</span></p>
<pre class="brush: js">$(&quot;#my_select :selected&quot;).remove();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>6)</strong> Удалить первый элемент</span></p>
<pre class="brush: js">$(&quot;#my_select :first&quot;).remove();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>7)</strong> Удалить последний элемент</span></p>
<pre class="brush: js">$(&quot;#my_select :last&quot;).remove();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>8)</strong> Удалить элемент, у которого value='2'</span></p>
<pre class="brush: js">$(&quot;#my_select option[value=&#039;2&#039;]&quot;). remove();
сокращенно:
$(&quot;#my_select [value=&#039;2&#039;]&quot;). remove();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>9) </strong>Очистить весь список &lt;select&gt;</span></p>
<pre class="brush: js">$(&quot;#my_select&quot;).empty();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong><span style="color: #333399;">10)</span></strong> Перебрать все элементы списка &lt;select&gt;</span></p>
<pre class="brush: js">$(&#039;#my_select option&#039;).each(function(){
alert(this.text);
});</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>11)</strong> Сделать выбранным последний элемент</span></p>
<pre class="brush: js">$(&quot;#my_select :last&quot;).attr(&quot;selected&quot;, &quot;selected&quot;);</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>12)</strong> Сделать выбранным второй элемент</span></p>
<pre class="brush: js">$(&quot;#my_select :nth-child(2)&quot;).attr(&quot;selected&quot;, &quot;selected&quot;);</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>13)</strong> Сделать выбранным элемент, содержащий текст 'two'</span></p>
<pre class="brush: js">$(&quot;#my_select :contains(&#039;two&#039;)&quot;).attr(&quot;selected&quot;, &quot;selected&quot;);</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>14)</strong> Сделать выбранным элемент, value которого = 2</span></p>
<pre class="brush: js">$(&quot;#my_select [value=&#039;2&#039;]&quot;).attr(&quot;selected&quot;, &quot;selected&quot;);</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>15) </strong>Добавить элемент в начало списка &lt;select&gt;</span></p>
<pre class="brush: js">$(&quot;#my_select&quot;).prepend( $(&#039;&lt;option value=&quot;0&quot;&gt;zero&lt;/option&gt;&#039;));</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>16) </strong>Добавить элемент в конец списка &lt;select&gt;</span></p>
<pre class="brush: js">$(&quot;#my_select&quot;).append( $(&#039;&lt;option value=&quot;4&quot;&gt;four&lt;/option&gt;&#039;));</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>17)</strong> Добавить новый элемент после второго</span></p>
<pre class="brush: js">$(&quot;#my_select option:nth-child(2)&quot;).after($(&#039;&lt;option value=&quot;22&quot;&gt;twotwo&lt;/option&gt;&#039;));</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>18) </strong>Количество элементов option в </span><span style="color: #333399;">списке &lt;select&gt;</span></p>
<pre class="brush: js">$(&quot;select[id=my_select] option&quot;).size();</pre>
<p style="padding-left: 30px;">
<p><span style="color: #333399;"><strong>19) </strong>Проверяем, выбран ли элемент в списке select</span><span style="color: #333399;">списке &lt;select&gt;</span></p>
<pre class="brush: js">if($(&quot;#my_select&quot;).val())</pre>
<p style="padding-left: 30px;">
<p>На этом пока все.</p>
<p>Если что-то не упомянул, пишите в комментариях!</p>


<!-- Begin SexyBookmarks Menu Code -->
<noindex><div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.webnotes.com.ua/index.php/archives/699&amp;title=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select+-+<br />
<b>Notice</b>:  Undefined index:  alias in <b>/home/shared_useracct/e7t.us/create.php</b> on line <b>9</b><br />
http://e7t.us/jtr6+(via+@niceteg)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.webnotes.com.ua/index.php/archives/699&amp;title=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.webnotes.com.ua/index.php/archives/699&amp;t=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.webnotes.com.ua/index.php/archives/699&amp;t=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-bobrdobr">
			<a href="http://bobrdobr.ru/addext.html?url=http://www.webnotes.com.ua/index.php/archives/699&amp;title=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Share this on BobrDobr">Share this on BobrDobr</a>
		</li>
		<li class="sexy-yandex">
			<a href="http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&amp;lurl=http://www.webnotes.com.ua/index.php/archives/699&amp;lname=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Add this to Yandex.Bookmarks">Add this to Yandex.Bookmarks</a>
		</li>
		<li class="sexy-memoryru">
			<a href="http://memori.ru/link/?sm=1&amp;u_data[url]=http://www.webnotes.com.ua/index.php/archives/699&amp;u_data[name]=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Add this to Memory.ru">Add this to Memory.ru</a>
		</li>
		<li class="sexy-100zakladok">
			<a href="http://www.100zakladok.ru/save/?bmurl=http://www.webnotes.com.ua/index.php/archives/699&amp;bmtitle=jQuery+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81+select" rel="nofollow" title="Add this to 100 bookmarks">Add this to 100 bookmarks</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.webnotes.com.ua/index.php/archives/699/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div></noindex>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.webnotes.com.ua/index.php/archives/699/feed</wfw:commentRss>
		<slash:comments>7</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! -->