<?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>iuttu &#187; mootools</title> <atom:link href="http://www.iuttu.com/tag/mootools/feed/" rel="self" type="application/rss+xml" /><link>http://www.iuttu.com</link> <description>Desarrollo web</description> <lastBuildDate>Mon, 23 Jan 2012 16:52:04 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>De Mootools a jQuery: comprobar si un elemento existe</title><link>http://www.iuttu.com/2009/03/de-mootools-a-jquery-comprobar-si-un-elemento-existe/</link> <comments>http://www.iuttu.com/2009/03/de-mootools-a-jquery-comprobar-si-un-elemento-existe/#comments</comments> <pubDate>Sun, 15 Mar 2009 11:26:01 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[Programación]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[frameworks]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[mootools]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=190</guid> <description><![CDATA[Para los que estamos acostumbrados a mootools, nos es habitual comprobar si un elemento (tag html con id) existe antes de lanzar los scripts, siempre lo hacemos de la misma manera: 1 if &#40;$&#40;&#34;elemento&#34;&#41;&#41; &#123; alert&#40;&#34;adelaaaaaaaanteee&#34;&#41;; &#125; Pero si pasamos a jQuery, vemos que si lo hacemos así, la expresión siempre devolverá cierto. Ya que [...]]]></description> <content:encoded><![CDATA[<p>Para los que estamos acostumbrados a <a
href="http://www.mootools.net">mootools</a>, nos es habitual comprobar si un elemento (tag html con id) existe antes de lanzar los scripts, siempre lo hacemos de la misma manera:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;elemento&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;adelaaaaaaaanteee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>Pero si pasamos a <a
href="http://jquery.com">jQuery</a>, vemos que si lo hacemos así, la expresión siempre devolverá <strong>cierto</strong>. Ya que la función $(&#8220;&#8221;) en <a
href="http://jquery.com">jQuery</a> siempre devuelve un array de elementos. Sabiendo esto, lo que tenemos que comprobar para saber si un elemento existe, es comprobar la longitud del array que  nos devuelve:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;elemento&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;adelaaaaaanteee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>Ya puestos, en <a
href="http://www.dojotoolkit.org/">dojo</a> tendríamos que hacer esto:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'elemento'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;adelaaaaaanteee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2009/03/de-mootools-a-jquery-comprobar-si-un-elemento-existe/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Cambiar evento onChange de un select con mootools</title><link>http://www.iuttu.com/2008/10/cambiar-evento-onchange-de-un-select-con-mootools/</link> <comments>http://www.iuttu.com/2008/10/cambiar-evento-onchange-de-un-select-con-mootools/#comments</comments> <pubDate>Wed, 08 Oct 2008 19:23:48 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[Programación]]></category> <category><![CDATA[mootools]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=47</guid> <description><![CDATA[En un proyecto reciente, tenímos la necesidad de que, dependiendo de X factores, la función a la que llamase el evento onChange de varios combos Select debía ir cambiando: 1 2 3 4 &#60;select id=&#34;slSelect&#34; onchange=&#34;alert(1)&#34;&#62; &#60;option value=&#34;1&#34;&#62;hola&#60;/option&#62; &#60;option value=&#34;2&#34;&#62;que tal&#60;/option&#62; &#60;/select&#62; En mootools, tenemos varias funciones para eliminar eventos de objetos: $(element).removeEvent() y $(element).removeEvents(), [...]]]></description> <content:encoded><![CDATA[<p>En un proyecto reciente, tenímos la necesidad de que, dependiendo de X factores, la función a la que llamase el evento <strong>onChange</strong> de varios combos <strong>Select</strong> debía ir cambiando:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slSelect&quot;</span> <span style="color: #000066;">onchange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;alert(1)&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>hola<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>que tal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></td></tr></table></div><p>En mootools, tenemos varias funciones para eliminar eventos de objetos: $(element).<a
href="http://www.mootools.net/docs/Element/Element.Event#Element:removeEvent" target="_blank">removeEvent</a>() y $(element).<a
href="http://www.mootools.net/docs/Element/Element.Event#Element:removeEvents" target="_blank">removeEvents</a>(), pero, misteriosamente, no tienen ningún efecto cuando se aplica a un objeto de tipo <strong>Select</strong>. ¿Y si en vez de un evento, el código <strong>onchange=&#8221;alert(1)&#8221;</strong> fuera interpretado como una propiedad de objeto? Pues efectivamente, la única forma de quitar (para después añadir otro) un evento <strong>onchange</strong> es anulando la propiedad del objeto, en <a
href="http://www.mootools.net" target="_blank">mootools</a> sería así:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slSelect&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;onchange&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Probado en FF3, IE6, IE7 y Safari. En la página siguiente os dejo el código del ejemplo&#8230;</p><p><span
id="more-144"></span></p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>TEST<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mootools.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span>
function changeOnChange() {
    $(&quot;slSelect&quot;).removeProperty(&quot;onchange&quot;);
}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slSelect&quot;</span> <span style="color: #000066;">onchange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;alert(1)&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>hola<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>que tal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cambia onchange&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;changeOnChange();&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2008/10/cambiar-evento-onchange-de-un-select-con-mootools/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 7/14 queries in 0.015 seconds using disk: basic

Served from: www.iuttu.com @ 2012-02-06 14:52:42 -->
