??xml version="1.0" encoding="utf-8" standalone="yes"?>仙踪林久久久久久久999,在线精品亚洲欧美日韩国产,一本大道香蕉久在线播放29http://www.aygfsteel.com/aoneany/category/31013.htmlƲ上天堂Q先下地?/description>zh-cnMon, 23 Apr 2012 04:08:52 GMTMon, 23 Apr 2012 04:08:52 GMT60javascrip对象中的函数callback对象中的Ҏ(gu)http://www.aygfsteel.com/aoneany/articles/375487.html沙漠中的?/dc:creator>沙漠中的?/author>Sat, 21 Apr 2012 15:35:00 GMThttp://www.aygfsteel.com/aoneany/articles/375487.htmlhttp://www.aygfsteel.com/aoneany/comments/375487.htmlhttp://www.aygfsteel.com/aoneany/articles/375487.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/375487.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/375487.html当在函数cM的某一个对象,需要回调类中的某一个方法时Q可以通过如下方式实现?br />Test = function(testFuncObj){
var testFunc = testFuncObj;
var _this = this;
this.render = function(parent){
testFunc.onClick(_this.onClick)
}
this.onClick = function(node){
alert(node.text);
}
}


]]>
javascript命o(h)行完成自动添加受信Q站点http://www.aygfsteel.com/aoneany/articles/364250.html沙漠中的?/dc:creator>沙漠中的?/author>Fri, 18 Nov 2011 07:30:00 GMThttp://www.aygfsteel.com/aoneany/articles/364250.htmlhttp://www.aygfsteel.com/aoneany/comments/364250.htmlhttp://www.aygfsteel.com/aoneany/articles/364250.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/364250.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/364250.html<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
var WshShell=new ActiveXObject("WScript.Shell"); 
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\YouTest.com",""); 
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\YouTest.com\\www",""); 
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\YouTest.com\\www\\http","2","REG_DWORD"); 
alert("写入成功"); 

//-->
</SCRIPT> 

 



]]>
Java实现一个用户在同一旉只登陆一?/title><link>http://www.aygfsteel.com/aoneany/articles/272005.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Thu, 21 May 2009 08:02:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/272005.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/272005.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/272005.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/272005.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/272005.html</trackback:ping><description><![CDATA[<p>保证|站用户Q或理员)(j)在同一旉只登陆一ơ在很多场合是很必要的!下面举一个基于Javaq_实现的例子?br />     <strong>W一步:(x)创徏SessionListenterc?/strong></p> <p> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">import</span><span style="color: #000000"> javax.servlet.http.HttpSession;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> javax.servlet.http.HttpSessionEvent;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> javax.servlet.http.HttpSessionListener;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.apache.log4j.Logger;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.jpxx.sw.Constants;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.jpxx.sw.Factory; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_222_353_Open_Image" onclick="this.style.display='none'; Codehighlighter1_222_353_Open_Text.style.display='none'; Codehighlighter1_222_353_Closed_Image.style.display='inline'; Codehighlighter1_222_353_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_222_353_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_222_353_Closed_Text.style.display='none'; Codehighlighter1_222_353_Open_Image.style.display='inline'; Codehighlighter1_222_353_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_222_353_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_222_353_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 该监听器用于监听后台理员登陆。只允许l一理员在同一旉登陆一ơ?br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> Jun Li<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@version</span><span style="color: #008000">  $Revision: 1.0.2 $, $Date: 2009/01/05 $<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@since</span><span style="color: #008000"> 1.0.0<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> <img id="Codehighlighter1_415_1053_Open_Image" onclick="this.style.display='none'; Codehighlighter1_415_1053_Open_Text.style.display='none'; Codehighlighter1_415_1053_Closed_Image.style.display='inline'; Codehighlighter1_415_1053_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_415_1053_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_415_1053_Closed_Text.style.display='none'; Codehighlighter1_415_1053_Open_Image.style.display='inline'; Codehighlighter1_415_1053_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> SessionListener </span><span style="color: #0000ff">implements</span><span style="color: #000000"> HttpSessionListener </span><span id="Codehighlighter1_415_1053_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_415_1053_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    Logger log </span><span style="color: #000000">=</span><span style="color: #000000"> Factory.getSingletonInstance().getLogger(SessionListener.</span><span style="color: #0000ff">class</span><span style="color: #000000">);<br /> <img id="Codehighlighter1_556_562_Open_Image" onclick="this.style.display='none'; Codehighlighter1_556_562_Open_Text.style.display='none'; Codehighlighter1_556_562_Closed_Image.style.display='inline'; Codehighlighter1_556_562_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_556_562_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_556_562_Closed_Text.style.display='none'; Codehighlighter1_556_562_Open_Image.style.display='inline'; Codehighlighter1_556_562_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> sessionCreated(HttpSessionEvent event) </span><span id="Codehighlighter1_556_562_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_556_562_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_623_1051_Open_Image" onclick="this.style.display='none'; Codehighlighter1_623_1051_Open_Text.style.display='none'; Codehighlighter1_623_1051_Closed_Image.style.display='inline'; Codehighlighter1_623_1051_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_623_1051_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_623_1051_Closed_Text.style.display='none'; Codehighlighter1_623_1051_Open_Image.style.display='inline'; Codehighlighter1_623_1051_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> sessionDestroyed(HttpSessionEvent event) </span><span id="Codehighlighter1_623_1051_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_623_1051_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        HttpSession session </span><span style="color: #000000">=</span><span style="color: #000000"> event.getSession();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> 获取存储理员的session</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        Object o </span><span style="color: #000000">=</span><span style="color: #000000"> session.getAttribute(Constants.JPXX_ADMIN_LOGIN_USERNAME_SESSION);<br /> <img id="Codehighlighter1_807_1045_Open_Image" onclick="this.style.display='none'; Codehighlighter1_807_1045_Open_Text.style.display='none'; Codehighlighter1_807_1045_Closed_Image.style.display='inline'; Codehighlighter1_807_1045_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_807_1045_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_807_1045_Closed_Text.style.display='none'; Codehighlighter1_807_1045_Open_Image.style.display='inline'; Codehighlighter1_807_1045_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(o</span><span style="color: #000000">!=</span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span id="Codehighlighter1_807_1045_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_807_1045_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            String userName </span><span style="color: #000000">=</span><span style="color: #000000"> o.toString();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000"> 登陆的用户都存储在Hashtable中,用户退出,从Hashtable中删除该用户</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            Factory.getUsers().remove(userName);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            log.error(</span><span style="color: #000000">"</span><span style="color: #000000">删除用户Q?/span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> userName </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">       </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> java.util.Date());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> 说明Q由于该cL自于目Q有很多操作都进行了(jin)装Q?zhn)E作修改卛_正常使用。注释掉LoggerQ声明一个静(rn)态变量private static Hashtable user = new Hashtable();在sessionCreated()Ҏ(gu)中将刚登陆的用户d到user中。?zhn)q需要写注销的页面(jsp或者servletQ,在页面里面调用session.invalidate(); 该方法会(x)触发sessionDestroyed()事gQ?br /> <br />  <strong>   W二部:(x)该监听器注册到web.xml<br /> </strong> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff"><</span><span style="color: #800000">listener</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />        </span><span style="color: #0000ff"><</span><span style="color: #800000">listener-class</span><span style="color: #0000ff">></span><span style="color: #000000">org.jpxx.sw.business.SessionListener</span><span style="color: #0000ff"></</span><span style="color: #800000">listener-class</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff"></</span><span style="color: #800000">listener</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> 说明Q仅仅依靠session监听器不可能100%可靠Q有可能用户不正帔R?例如直接关闭览器、系l断늭{?。针对直接关闭浏览器有如下解x(chng)案:(x)在被关闭的页面里面插入如下语句:(x)<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff"><</span><span style="color: #800000">body </span><span style="color: #ff0000">scroll</span><span style="color: #0000ff">="no"</span><span style="color: #ff0000"> onUnload</span><span style="color: #0000ff">="Jpxx.forceLogout();"</span><span style="color: #ff0000"> onbeforeunload</span><span style="color: #0000ff">="Jpxx.forceLogout();"</span><span style="color: #0000ff">></span></div> <p>Jpxx.forceLogout()Ҏ(gu)通过AJAX技术来强制注销用户Q即调用session.invalidate()Ҏ(gu)?</p> 转蝲:<a >http://www.jpxx.org/?tid=54</a> <img src ="http://www.aygfsteel.com/aoneany/aggbug/272005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2009-05-21 16:02 <a href="http://www.aygfsteel.com/aoneany/articles/272005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript字符串判?/title><link>http://www.aygfsteel.com/aoneany/articles/239274.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Fri, 07 Nov 2008 08:25:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/239274.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/239274.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/239274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/239274.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/239274.html</trackback:ping><description><![CDATA[<p>判断是否全ؓ(f)汉字</p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">/</span><span style="color: #000000">[</span><span style="color: #000000">^/</span><span style="color: #000000">x00</span><span style="color: #000000">-/</span><span style="color: #000000">xff]</span><span style="color: #000000">/</span><span style="color: #000000">g.test(s))   <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />   alert(</span><span style="color: #000000">"</span><span style="color: #000000">含有汉字</span><span style="color: #000000">"</span><span style="color: #000000">);     <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">else</span><span style="color: #000000">   <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />   alert(</span><span style="color: #000000">"</span><span style="color: #000000">全是字符</span><span style="color: #000000">"</span><span style="color: #000000">);</span></div> <p> </p> <p>var   strTest="试Test";   <br /> alert(strTest.length);   <br />  //昄?Q他把一个汉字当作一自字W,而我需要得到的l果?Q也是把汉字当成两个字W?/p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">var</span><span style="color: #000000"> strTest</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">试Test</span><span style="color: #000000">"</span><span style="color: #000000">;   <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />  alert(strTest.replace(</span><span style="color: #000000">/</span><span style="color: #000000">[</span><span style="color: #000000">^</span><span style="color: #000000">\x00</span><span style="color: #000000">-</span><span style="color: #000000">\xff]</span><span style="color: #000000">/</span><span style="color: #000000">g,'##').length);   </span></div> <p>以上Ҏ(gu)只能求汉字加子母的情情况Qؓ(f)求gؓ(f)1的情况就?x)生异怺(jin)</p> <p> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_31_227_Open_Image" onclick="this.style.display='none'; Codehighlighter1_31_227_Open_Text.style.display='none'; Codehighlighter1_31_227_Closed_Image.style.display='inline'; Codehighlighter1_31_227_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_31_227_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_31_227_Closed_Text.style.display='none'; Codehighlighter1_31_227_Open_Image.style.display='inline'; Codehighlighter1_31_227_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #000000">ADM.checkStrLen</span><span style="color: #000000">=</span><span style="color: #0000ff">function</span><span style="color: #000000">(value)</span><span id="Codehighlighter1_31_227_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_31_227_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">var</span><span style="color: #000000"> str,Num </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(value</span><span style="color: #000000">==</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> Num;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> <img id="Codehighlighter1_118_209_Open_Image" onclick="this.style.display='none'; Codehighlighter1_118_209_Open_Text.style.display='none'; Codehighlighter1_118_209_Closed_Image.style.display='inline'; Codehighlighter1_118_209_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_118_209_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_118_209_Closed_Text.style.display='none'; Codehighlighter1_118_209_Open_Image.style.display='inline'; Codehighlighter1_118_209_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">var</span><span style="color: #000000"> i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000"><</span><span style="color: #000000">value.length;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span id="Codehighlighter1_118_209_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_118_209_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        str </span><span style="color: #000000">=</span><span style="color: #000000"> value.substring(i,i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (str</span><span style="color: #000000"><=</span><span style="color: #000000">"</span><span style="color: #000000">~</span><span style="color: #000000">"</span><span style="color: #000000">)  </span><span style="color: #008000">//</span><span style="color: #008000">判断是否双字?/span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            Num</span><span style="color: #000000">+=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">else</span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            Num</span><span style="color: #000000">+=</span><span style="color: #000000">2</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> </span><span style="color: #0000ff">return</span><span style="color: #000000"> Num;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> }</span></span></div> <p>以上Ҏ(gu)能解x(chng)字,字母Q数据؜合的情况</p> <img src ="http://www.aygfsteel.com/aoneany/aggbug/239274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2008-11-07 16:25 <a href="http://www.aygfsteel.com/aoneany/articles/239274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>E序讄Extjs?wi)中CheckBox的选中和取消选中讄http://www.aygfsteel.com/aoneany/articles/223260.html沙漠中的?/dc:creator>沙漠中的?/author>Wed, 20 Aug 2008 06:36:00 GMThttp://www.aygfsteel.com/aoneany/articles/223260.htmlhttp://www.aygfsteel.com/aoneany/comments/223260.htmlhttp://www.aygfsteel.com/aoneany/articles/223260.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/223260.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/223260.html在Extjs中treepanel中树(wi)节点为checkboxcȝ节时Q有时候我们需要用E序来设|他的选中和取消选中状?br /> var nodes=tree.getChecked(); 
if(nodes && nodes.length){
 for(var i=0;i<nodes.length;i++){
  //讄UI状态ؓ(f)未选中状?br />   nodes[i].getUI().toggleCheck(false);
  //讄节点属性ؓ(f)未选中状?br />   nodes[i].attributes.checked=false;
 }
}
q样通过获取已选择的节点,用程序取消选择状?br /> 反之可以讄未选中节点选中状?/p>

]]>
JavaScript多线E技?/title><link>http://www.aygfsteel.com/aoneany/articles/215550.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Thu, 17 Jul 2008 09:23:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/215550.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/215550.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/215550.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/215550.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/215550.html</trackback:ping><description><![CDATA[<p>While increasingly more websites are fully or partially based on AJAX, it is still difficult to develop complicated AJAX applications. What is the main issue which causes this difficulty in developing AJAX applications? Is it asynchronous communication with the server, or is it GUI programming? Both are routinely performed by desktop window applications -- so why is development of AJAX applications which do the same things particularly difficult? </p> <p>Let’s consider this issue using a simple example. Suppose that you want to build a tree-structured bulletin board system which loads the data for each article by communicating with the server according to user requests rather than loading all articles at one time from the server. Each article has 4 pieces of information associated with it: a unique ID within the bulletin board system, the name of the person who posted the article, the content of the article, and an array of the IDs of its child articles. To begin with, let’s assume that there is a JavaScript function named <code>getArticle()</code> which is responsible for loading a single article. This function receives the integer ID of the article to be loaded as an argument, and it retrieves the data of the article with that ID from the server. It then returns an object which has the 4 pieces of information contained in that article: <code>id, name, content</code>, and <code>children</code>. An example of this function in use can be written like this: </p> <pre>function ( id ) {<br /> var a = getArticle(id);<br /> document.writeln(a.name + "<br>" + a.content);<br /> } </pre> <p>As you may notice, calling this function many times with the same article ID, however, requires communications with the server again and again for no good reason. To counter this problem, consider the function <code>getArticleWithCache()</code>, which is a <code>getArticle()</code> with a cache capability. In this example, the data loaded by <code>getArticle()</code> will be simply retained as a global variable: </p> <pre>var cache = {};<br /> function getArticleWithCache ( id ) {<br /> if ( !cache[id] ) {<br /> cache[id] = getArticle(id);<br /> }<br /> return cache[id];<br /> } </pre> <p>Now the articles that have been read are cached. Now, let’s consider the function <code>backgroundLoad()</code>, which loads the data of all articles based on this mechanism. This function aims to preload all of the child articles in the background while the user is reading a given article. Because the article data is tree structured, a recursive algorithm can easily be written which traverses the tree and allows all articles to be loaded: </p> <pre>function backgroundLoad ( ids ) {<br /> for ( var i=0; i < ids.length; i++ ) {<br /> var a = getArticleWithCache(ids[i]);<br /> backgroundLoad(a.children);<br /> }<br /> } </pre> <p>The <code>backgroundLoad()</code> function receives an array of IDs as an argument and applies our previously-defined <code>getArticleWithCache()</code> to each ID. This allows the data of the article corresponding to each ID to be cached. Then, by recursively calling <code>backgroundLoad()</code> on the IDs of the child articles of the loaded article, the entire article tree is cached. </p> <p>So far, everything looks good. If you have worked on AJAX application development, however, you should know that this naïve implementation won’t work successfully. The example has been based on the tacit understanding that <code>getArticle()</code> uses synchronous communication. As a general rule, however, JavaScript requires the use of asynchronous communication in communicating with the server because it has only a single thread. In terms of simplicity, processing everything (including GUI events and rendering), on one thread is a good programming model, because it eliminates the need to think about the complicated problems associated with thread synchronization. On the other hand, it presents a significant problem in developing applications –which appear responsive to the user because the single-thread environment cannot respond to users’ mouse clicking and/or key operation when the thread is working on something else (such as the <code>getArticle()</code> call). </p> <p>What happens if synchronous communication is carried out within this single-threaded environment? Synchronous communication stops the browser’s execution until the communication result is obtained. The thread cannot respond to users while waiting for the communication result because the call from the server has not been completed, and the thread will remain blocked until the call returns. For this reason, it can not respond to users while it is waiting for the server’s response and the browser therefore looks frozen. This also holds true for the execution of <code>getArticleWithCache()</code> and <code>backgroundLoad()</code>, which are based on <code>getArticle()</code>. Because may take a considerable amount of time to download all of the articles, the browser freezing during that time is a serious problem for <code>backgroundLoad()</code> - since the browser is frozen, it is not possible in the first place to achieve the goal of preloading the data in the background while users are reading articles, since the article will be unreadable. </p> <p>Since the use of synchronous communication creates a significant problem in usability as described above, JavaScript uses asynchronous communication as a general rule. Therefore, let’s rewrite the program above based on asynchronous communication. JavaScript requires asynchronous communications to be written in an event-driven programming style. In most instances, you specify a callback function which is called once the communication response has been received. For example, <code>getArticleWithCache()</code> defined above can be rewritten as: </p> <pre>var cache = {};<br /> function getArticleWithCache ( id, callback ) {<br /> if ( !cache[id] ) {<br /> callback(cache[id]);<br /> } else {<br /> getArticle(id, function( a ){<br /> cache[id] = a;<br /> callback(a);<br /> });<br /> }<br /> } </pre> <p>This program also internally calls the <code>getArticle()</code> function. It should be noted, however, that the version of <code>getArticle()</code> which is designed for asynchronous communication expects to receive a function as the second argument. When this version of <code>getArticle()</code> is called, it sends a request to the server, as before, however the function returns immediately without waiting for a response from the server. This means that when the execution is returned to the caller, the server response has not yet been retrieved. This allows the thread to work on other tasks until the server response is obtained and the callback function is called. As soon as this response is received from the server, the callback function specified as the second argument of <code>getArticle()</code> is invoked with the server’s response as an argument. Likewise, <code>getArticleWithCache()</code> has been changed so that it will expect a callback function as the second argument. This callback function will then be called within the callback function that is passed to <code>getArticle()</code> so that it will be executed after the server-communication is finished. </p> <p>You may think that the above rewriting alone is rather complicated, but the <code>backgroundLoad()</code> function involves even more complicated rewriting. It can be also rewritten to handle a callback function: </p> <pre>function backgroundLoad ( ids, callback ) {<br /> var i = 0;<br /> function l ( ) {<br /> if ( i < ids.length ) {<br /> getArticleWithCache(ids[i++], function( a ){<br /> backgroundLoad(a.children, l);<br /> });<br /> } else {<br /> callback();<br /> }<br /> }<br /> l();<br /> } </pre> <p>This rewritten <code>backgroundLoad()</code> function does not look much like our original function, however there is no difference in what they do. This means that both functions receive an array of IDs, call <code>getArticleWithCache()</code> on each element of the array, and recursively apply <code>backgroundLoad()</code> to the resultant child articles. However, it is not easy to recognize even the loop structure for the array, which was represented by a for-statement in the original program. Why are these two sets of functions that do the same thing so totally different from each other? </p> <p>The difference results from the fact that any function must return immediately after any function that requires server-communication, such as <code>getArticleWithCache()</code>. The callback function that should receive the server response cannot be called unless the original function is no longer executing. For JavaScript, it is not possible to suspend the program in the middle of loops, such as for-statements, and resume it later at the point where execution was suspended; the loop is therefore represented by recursively passing the callback function instead of using a loop syntax. For those who are familiar with Continuation-Passing Style (CPS), this is a manual implementation of CPS. Because no loop syntax can be used, even the simple program described earlier that traverses a tree requires complicated statements. The problem associated with event-driven programs is known as the <a >control flow problem</a>: loop and other control flow statements are likely to be difficult to understand.</p> <p>There is another problem: if you convert a function which does not use asynchronous communication into a function that uses asynchronous communication, the rewritten function will need to have a new parameter which is a callback functions. This poses a significant problem to existing APIs since our internal changes will not remain internal, but will result in broken APIs and changes by others using our API. </p> <p>What is the root cause of all of these problems? That’s right. The fact that JavaScript has only one thread causes the problems. Carrying out asynchronous communication on only one thread requires an event-driven program and complicated statements. If another thread could respond to users while the program is waiting for the server response, acrobatics like this would not be required. </p> <h3>Invitation to Multithreaded Programming</h3> <p>Let me talk about Concurrent.Thread, a library that allows JavaScript to use multiple threads, since this greatly eases the difficulty associated with asynchronous communication in the AJAX development mentioned above. This is a free-software library implemented in JavaScript, available under the Mozilla Public License / GNU General Public License. You can download the source code <a >from the website</a>. </p> <p>Let’s download and use the source code right away. Suppose that you have saved the downloaded source code as a file named Concurrent.Thread.js. Before doing anything else, let’s run the program below, which has a very naïve implementation: </p> <pre><script type="text/javascript" src="Concurrent.Thread.js"></script><br /> <script type="text/javascript"><br /> Concurrent.Thread.create(function(){<br /> var i = 0;<br /> while ( 1 ) {<br /> document.body.innerHTML += i++ + "<br>";<br /> }<br /> });<br /> </script> </pre> <p>Executing this program should display numbers starting with 0 in order. Numbers appear one after another, which you can view by scrolling the page. Now, let’s look at the source code in more detail. It uses a simple infinite loop as indicated by <code>while ( 1 )</code>. In ordinary cases, a JavaScript program like this continues to use the one and only thread, causing the browser to look frozen. Naturally, it does not allow you to scroll the screen. Then, why does the above program allow you to scroll? The key is <code>Concurrent.Thread.create()</code> located above while <code>( 1 )</code>. This is a method provided by the library; it is for creating a new thread. On a new thread, the function passed as the argument is executed. Let me slightly rewrite the program as follows: </p> <pre><script type="text/javascript" src="Concurrent.Thread.js"></script><br /> <script type="text/javascript"><br /> function f ( i ){<br /> while ( 1 ) {<br /> document.body.innerHTML += i++ + "<br>";<br /> }<br /> }<br /> Concurrent.Thread.create(f, 0);<br /> Concurrent.Thread.create(f, 100000);<br /> </script> </pre> <p>In this program we have a new function <code>f()</code>, which shows numbers repeatedly. This is defined at the top, and the <code>create()</code> method is called twice with <code>f()</code> as arguments. The second argument passed to the <code>create()</code> method is passed to <code>f()</code> without modification. Executing this program shows some small numbers starting with 0, which are followed by some large numbers starting with 100,000 and small numbers again that follow up the first series of small numbers. Like this, you can observe that the program shows alternating lines of small numbers and large numbers. This indicates that two threads are running concurrently. </p> <p>Let me show you another use of Concurrent.Thread. In the above example, the <code>create()</code> method was called to create a thread. It is also possible to create a thread without calling any library APIs at all. For example, the former example can be expressed as: </p> <pre><script type="text/javascript" src="Concurrent.Thread.js"></script><br /> <script type="text/x-script.multithreaded-js"><br /> var i = 1;<br /> while ( 1 ) {<br /> document.body.innerHTML += i++ + "<br>";<br /> }<br /> </script> </pre> <p>Inside the script tag, an infinite loop is written simply in JavaScript. You should take note of the type attribute of the tag: an unfamiliar value (<code>text/x-script.multithreaded-js</code>) is assigned to it. If this attribute is assigned to the script tag, then Concurrent.Thread executes the content of the tag on a new thread. You should remember that, in this case as well, the library body of Concurrent.Thread must be included. </p> <p>With Concurrent.Thread, it is possible to switch execution context from one thread to another as needed even if you write a long and continuous program. Let me briefly talk about how this behavior is achieved. In short, code conversion is used. Very roughly speaking, the function passed to the <code>create()</code> method is first converted to a character string, which is then rewritten so that it can be executed on a piecemeal basis. Then, the rewritten function is executed little by little on the scheduler. The scheduler is responsible for coordinating multiple threads. In other words, it makes adjustments so that each of the rewritten functions will be evenly executed. Concurrent.Thread actually does not create new threads but simply simulates a multi-threaded environment on the original single thread. </p> <p>Although the converted functions appear to be running on different threads, there is actually only one thread running everything. Carrying out synchronous communication within the converted functions will still cause the browser to freeze. You may think that our original problem has not been solved at all, however you don’t have to worry. Concurrent.Thread provides a purpose-built communications library which is implemented using the asynchronous JavaScript communication style and which is designed to allow the other threads to work even when a thread is waiting for a response from the server. This communications library is found under the <code>Concurrent.Thread.Http</code> namespace. For example, it is used as follows: </p> <pre><script type="text/javascript" src="Concurrent.Thread.js"></script><br /> <script type="text/x-script.multithreaded-js"><br /> var req = Concurrent.Thread.Http.get(url, ["Accept", "*"]);<br /> if (req.status == 200) {<br /> alert(req.responseText);<br /> } else {<br /> alert(req.statusText);<br /> }<br /> </script> </pre> <p>The <code>get()</code> method retrieves the content of the specified URL using <code>HTTP GET</code>, as its name suggests. It takes a target URL as the first argument and an array representing HTTP header fields as the optional second argument. The <code>get()</code> method communicates with the server and returns an XMLHttpRequest object as the return value when it has received the server response. When the <code>get()</code> method returns, the response had been received. It is not necessary to use a callback function to receive the result. Naturally, there is no worry that the browser freezes while the program is waiting a response from the server. In addition, the <code>post()</code> method can be used to send data to the server: </p> <pre><script type="text/javascript" src="Concurrent.Thread.js"></script><br /> <script type="text/x-script.multithreaded-js"><br /> var req = Concurrent.Thread.Http.post(url, "key1=val1&key2=val2");<br /> alert(req.statusText);<br /> </script> </pre> <p>The <code>post() method takes a destination URL as the first argument and content body to be sent as the second argument. As with the <code>get()</code> method, you can also assign header fields by the optional third argument. </code></p> <p>If you implement <code>getArticle()</code> in the first example using this communications library, then you can quickly write <code>getArticleWithCache()</code>, <code>backgroundLoad()</code>, and other functions that use <code>getArticle()</code> using the naïve method shown at the beginning of this article. Even when that version of <code>backgroundLoad()</code> is reading article data, another thread can respond to users as a matter of course, and the browser therefore does not freeze. Now, do you understand how useful it is to use multiple threads in JavaScript? <br /> </p> <p><br />  </p> <p>转蝲:http://www.infoq.com/articles/js_multithread</p> <img src ="http://www.aygfsteel.com/aoneany/aggbug/215550.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2008-07-17 17:23 <a href="http://www.aygfsteel.com/aoneany/articles/215550.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>document.createElement("input")动态创建html元素时checkbox和radio默认选中的问?/title><link>http://www.aygfsteel.com/aoneany/articles/206940.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Tue, 10 Jun 2008 08:27:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/206940.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/206940.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/206940.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/206940.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/206940.html</trackback:ping><description><![CDATA[<p><font style="background-color: #c7edcc">最q研IcreateElement的时候发C个奇怪的问题 <br /> <br /> var echkbox=document.createElement("input");<br /> echkbox.setAttribute("type","checkbox");<br /> echkbox.setAttribute("id","inputid");<br /> echkbox.setAttribute("name","inputname");<br /> echkbox.setAttribute("value","inputvalue");<br /> echkbox.setAttribute("checked","checked");<br /> var addhere=document.getElementById("someElementId");<br /> addhere.appendChild(echkbox);<br /> alert(document.getElementById("inputid").checked);</font></p> <p><font style="background-color: #c7edcc">ie7昄出来的checkbox居然是未选中的但是alert出来的却是trueQ而FF一切正?br /> 后来查了(jin)半天资料说是ie昄的时候只对状态改变比较敏?br /> Ҏ(gu)<br /> var echkbox=document.createElement("input");<br /> echkbox.setAttribute("type","checkbox");<br /> echkbox.setAttribute("id","inputid");<br /> echkbox.setAttribute("name","inputname");<br /> echkbox.setAttribute("value","inputvalue");<br /> var addhere=document.getElementById("someElementId");<br /> addhere.appendChild(echkbox);<br /> echkbox.setAttribute("checked","checked");<br /> alert(document.getElementById("inputid").checked);</font></p> <p><font style="background-color: #c7edcc">一切ok<br /> radio同样是这U情c(din)?/font></p> 转自 someone's somethingI间 <img src ="http://www.aygfsteel.com/aoneany/aggbug/206940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2008-06-10 16:27 <a href="http://www.aygfsteel.com/aoneany/articles/206940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>float在IE和firefox中的使用http://www.aygfsteel.com/aoneany/articles/203012.html沙漠中的?/dc:creator>沙漠中的?/author>Mon, 26 May 2008 11:09:00 GMThttp://www.aygfsteel.com/aoneany/articles/203012.htmlhttp://www.aygfsteel.com/aoneany/comments/203012.htmlhttp://www.aygfsteel.com/aoneany/articles/203012.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/203012.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/203012.html在IE和firefox中,Ҏ(gu)档对象DIV标签的停靠方式不?如在IE中他p别float的属性,但是在firefox中他需?/font>cssFloat

firefox下代?/p>

var 
oDiv
=document.createElement("div"); 
oDiv.style.width
="101";          
var iDiv1=document.createElement("div");           iDiv1.style.background="#FFEE00"
iDiv1.style.width
=50;    iDiv1.style.cssFloat="left";    iDiv1.innerHTML=""
iDiv1.style.height
="20"; oDiv.appendChild(iDiv1);

var iDiv2=document.createElement("div");
iDiv2.style.background
="#881200";
iDiv2.style.width
=50;
iDiv2.style.cssFloat
="left";
iDiv2.innerHTML
="中间?/span>";
iDiv2.style.height
="20";
oDiv.appendChild(iDiv2);

var iDiv3=document.createElement("div");
iDiv3.style.background
="#235500";
iDiv3.style.width
=1;
iDiv3.style.height
="20";
iDiv3.style.cssFloat
="left";
iDiv3.style.overflow
="hidden";
oDiv.appendChild(iDiv3);

document.getElementById(
"test").innerHTML=oDiv.innerHTML;

IE代码

var 
oDiv
=document.createElement("div");         oDiv.style.width="101";          
var 
iDiv1
=document.createElement("div");           iDiv1.style.background="#FFEE00"
iDiv1.style.width
=50;    iDiv1.style.float="left";    iDiv1.innerHTML=""
iDiv1.style.height
="20"; oDiv.appendChild(iDiv1);

var iDiv2=document.createElement("div");
iDiv2.style.background
="#881200";
iDiv2.style.width
=50;
iDiv2.style.
float="left";
iDiv2.innerHTML
="中间?/span>";
iDiv2.style.height
="20";
oDiv.appendChild(iDiv2);

var iDiv3=document.createElement("div");
iDiv3.style.background
="#235500";
iDiv3.style.width
=1;
iDiv3.style.height
="20";
iDiv3.style.
float="left";
iDiv3.style.overflow
="hidden";
oDiv.appendChild(iDiv3);

document.getElementById(
"test").innerHTML=oDiv.innerHTML;


]]>
javascript适别不同的浏览器和^?/title><link>http://www.aygfsteel.com/aoneany/articles/203010.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Mon, 26 May 2008 10:56:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/203010.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/203010.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/203010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/203010.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/203010.html</trackback:ping><description><![CDATA[<font style="background-color: #c7edcc">在不同的q_和不同的览器中对javascript的支持也不同Q在我们写javascriptq程中,需要尽量避免他的不兼容性,一般都采用最公母法Q尽量满不同^台和不同览器的我需要,但是对于某些特定功能Q我需要在不同的浏览中实现不同的方法,因此我们必能实别不同的^台和览?br /> 如下是适别不同的^台和览器方?br /> //览器版?br /> ADM.BROWERVERSION=parseInt(navigator.appVersion);<br /> //是否为NETSCAPE览?br /> ADM.ISNETSCAPE=navigator.appName.indexOf("Netscape")!=-1;<br /> //是否为IE览?br /> ADM.ISIE=navigator.appName.indexOf("Microsoft")!=-1;<br /> //代理<br /> ADM.AFENT=navigator.appName.toLowerCase();<br /> //是否为WINDOWSq_?br /> ADM.ISWINDOWS=ADM.AFENT.indexOf("win")!=-1;<br /> //是否为MACq_?br /> ADM.ISMAC=ADM.AFENT.indexOf("mac")!=-1;<br /> //是否为UNIXq_?br /> ADM.ISUNIX=ADM.AFENT.indexOf("x11")!=-1;</font> <img src ="http://www.aygfsteel.com/aoneany/aggbug/203010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2008-05-26 18:56 <a href="http://www.aygfsteel.com/aoneany/articles/203010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>?wi){化ؓ(f)表格囑֞展现http://www.aygfsteel.com/aoneany/articles/199752.html沙漠中的?/dc:creator>沙漠中的?/author>Sat, 10 May 2008 14:04:00 GMThttp://www.aygfsteel.com/aoneany/articles/199752.htmlhttp://www.aygfsteel.com/aoneany/comments/199752.htmlhttp://www.aygfsteel.com/aoneany/articles/199752.html#Feedback1http://www.aygfsteel.com/aoneany/comments/commentRss/199752.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/199752.html做过olap开发的人可能都知道Q他查出来的表的l构是一|(wi)Q我们需要把?wi){化ؓ(f)表,通过表格的样式用囑֞更加客观的展现出?/span>

我们有一这L(fng)?/span>


我们现在要把q棵?wi){化成如下的表格样?/span>

 

通过表格我们可以看出Q他有三部䆾Q主栏,宾栏Q主体,而主栏,是一颗向叛_开的树(wi)Q宾栏是一颗向下展开的树(wi)Q而主体部份则是一个表?/span>

表格的整体布局


L

HTMLl构

<DIV>

       <DIV>

                     <DIV>李宁DIV>

                     <DIV></DIV>

       </DIV>

    <DIV></DIV>

    <DIV>

        <DIV>?/span>/DIV>

        <DIV></DIV>

        <DIV>上衣DIV>

        <DIV></DIV>

    </DIV>

    <DIV></DIV>

</DIV>

宾栏

HTMLl构

<DIV>

       <DIV>

                     <DIV>大区</DIV>

                     <DIV></DIV>

       </DIV>

    <DIV></DIV>

    <DIV>

        <DIV>华北</DIV>

        <DIV></DIV>

        <DIV>华中</DIV>

        <DIV></DIV>

    </DIV>

    <DIV></DIV>

</DIV>
M

HTMLl构

<DIV>

       <DIV>

              <DIV>l</DIV>

              <DIV></DIV>

       </DIV>

       <DIV>

       </DIV>

</DIV>

其中在HTML中边框全部采用宽度或高度?PX的DIV构成
在div布局中,横向展开采用的属性是float="left"

我设计的Jscȝ构图如下

一个由?wi){化ؓ(f)表格的程序就完成Q但是在开发过E中Q有时候也到一些问题,如效率等Q如有哪位对q控件或报表开发方面有兴趣的,大家一起交?span lang="EN-US">



]]>
Firebug的?/title><link>http://www.aygfsteel.com/aoneany/articles/198592.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Mon, 05 May 2008 15:05:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/198592.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/198592.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/198592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/198592.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/198592.html</trackback:ping><description><![CDATA[<h3>什么是Firebug</h3> <p>从事?jin)数q的Web开发工作,来觉得现在对WEB开发有?jin)更高的要求。要写出漂亮的HTML代码Q要~写_致的CSS样式表展C每个页面模块;要调?a >javascript</a>l页面增加一些更zL的要素;要用Ajaxl用户带来更好的体验。一个优U的WEB开发h员需要顾?qing)更多层面,才能交出一份同样优U的作业。ؓ(f)帮助q大正处于Web2.0z流中的开发h员,在这里ؓ(f)大家介绍一ƾ轻巧灵zȝ辅助开发工兗?/p> <p>Firebug是Firefox下的一Ƒּ发类插gQ现属于<a >Firefox</a>的五星强力推荐插g之一。它集HTML查看和编辑、Javascript控制台、网l状늛视器于一体,是开发JavaScript、CSS、HTML和Ajax的得力助手。Firebug如同一把精巧的瑞士军刀Q从各个不同的角度剖析Web面内部的细节层面,lWeb开发者带来很大的便利。这是一ƾ让人爱不释手的插gQ如果你以前没有接触q它Q也许在阅读本文之后Q会(x)有一试的Ʋ望。笔者在撰写此文的时候,正逢Firebug发布1.0正式版,q不能不说是Uy合?br /> </p> <h3>应用</h3> <p>Firebug插g虽然功能强大Q但是它已经和Firefox览器无~地l合在一P使用单直观。如果你担心(j)它会(x)占用太多的系l资源,也可以方便地启用/关闭q个插gQ甚至针对特定的站点开启这个插件?/p> <p>在安装好插g之后Q先用Firefox览器打开需要测试的面Q然后点d下方的绿色按钮或使用快捷键F12唤出Firebug插gQ它?x)将当前面分成上下两个框架Q如?所C?/p> <p>?QFirebug插g展开囄<br /> <img style="width: 522px; height: 128px" height="128" alt="firebug插g展开囄" src="http://www.ooso.net/wp-content/uploads/2007/firebug1.gif" width="522" /><br /> 从图1中看刎ͼFirebug?个主要的Tab按钮Q下文将主要介绍介绍q几斚w的功能?/p> <table cellpadding="4" border="1"> <tbody> <tr> <td>Console</td> <td>HTML</td> <td>CSS</td> <td>Script</td> <td>Dom</td> <td>Net</td> </tr> <tr> <td>控制?/td> <td>Html查看?/td> <td>Css查看?/td> <td>脚本条时?</td> <td>Dom查看?/td> <td>|络状况监视</td> </tr> </tbody> </table> <h3>Console 控制?/h3> <p>控制台能够显C当前页面中的javascript错误以及(qing)警告Qƈ提示出错的文件和行号Q方便调试,q些错误提示比v览器本w提供的错误提示更加详细且具有参考h(hun)倹{而且在调试Ajax应用的时候也是特别有用,你能够在控制台里看到每一个XMLHttpRequestshpost出去的参数、URLQhttp头以?qing)回馈的内容Q原本似乎在q后黑匣子里q作的程序被清清楚楚地展C在你面前?/p> <p>象C shell或Python shell一P你还能在控制C查看变量内容Q直接运行javascript语句Q就是大段的javascriptE序也能够正运行ƈ拿到q行期的信息?/p> <p>控制台还有个重要的作用就是查看脚本的log, 从前你也怹(fn)惯了(jin)使用alert来打印变量,但是Firebugl我们带来了(jin)一个新朋友 —?console.log, 最单的打印日志的语法是q样的:(x) </p> <div id="wmqeeuq" class="igBar"><span id="lcode-1"><a onclick="javascript:showCodeTxt('code-1'); return false;" >PLAIN TEXT</a></span></div> <div id="wmqeeuq" class="syntax_hilite"><span id="wmqeeuq" class="langName">CODE:</span> <div class="wmqeeuq" id="code-1"> <div id="wmqeeuq" class="code"> <ol> <li style="font-weight: normal; color: #3a6a8b; font-style: normal; font-family: 'Courier New', Courier, monospace"> <div style="font-weight: normal; font-family: 'Courier New', Courier, monospace">console.<span>log</span><span style="font-weight: bold; color: #006600">(</span><span style="color: #cc0000">"hello world"</span><span style="font-weight: bold; color: #006600">)</span> </div> </li> </ol> </div> </div> </div> <p>如果你有一堆参数需要组合在一赯出,可以写成q样Q?/p> <div id="wmqeeuq" class="igBar"><span id="lcode-2"><a onclick="javascript:showCodeTxt('code-2'); return false;" >PLAIN TEXT</a></span></div> <div id="wmqeeuq" class="syntax_hilite"><span id="wmqeeuq" class="langName">CODE:</span> <div class="wmqeeuq" id="code-2"> <div id="wmqeeuq" class="code"> <ol> <li style="font-weight: normal; color: #3a6a8b; font-style: normal; font-family: 'Courier New', Courier, monospace"> <div style="font-weight: normal; font-family: 'Courier New', Courier, monospace">console.<span>log</span><span style="font-weight: bold; color: #006600">(</span><span style="color: #800000">2</span>,<span style="color: #800000">4</span>,<span style="color: #800000">6</span>,<span style="color: #800000">8</span>,<span style="color: #cc0000">"foo"</span>,bar<span style="font-weight: bold; color: #006600">)</span>. </div> </li> </ol> </div> </div> </div> <p>Firebug的日志输出有多种可选的格式以及(qing)语法Q甚臛_以定制彩色输出,比v单调的alertQ显然更加方便,限于幅Q这里不做详l说明,但是有志于提高debug效率的读者,可以到Firebug的官方站点(见附录)(j)查看更详l的教程?/p> <p>?Q?在控制台里调试javascript<br /> <img style="width: 532px; height: 202px" height="202" alt="在控制台里调试javascript" src="http://www.ooso.net/wp-content/uploads/2007/firebug2.gif" width="532" /></p> <h3>查看和修改HTML</h3> <p>W一ơ看到Firebug强大的HTML代码查看器,p得它与众不同Q相比于Firefox自带的HTML查看器,它的功能强大?jin)许多?HTML</p> <p>首先你看到的是已l经q格式化的HTML代码Q它有清晰的层次Q你能够方便地分辨出每一个标{之间的从属q行关系Q标{折叠功能能够帮助你集中精力分析代码。源代码上方q标记出?jin)DOM的层ơ,如图3所C,它清楚地列出?jin)一个hml元素的parent、child以及(qing)root元素Q配合F(tun)irebug自带的CSS查看器用,?x)给div+css面分析~写带来很大的好处。你q可以在HTML查看器中直接修改HTML源代码,q在览器中W一旉看到修改后的效果Q光凭这一点就?x)让许多面设计师死心(j)塌地地成?f)Firebug的粉丝了(jin)?/p> <p>有时候页面中的javascript?x)根据用L(fng)动作如鼠标的onmouseover来动态改变(sh)些HTML元素的样式表或背景色QHTML查看器会(x)页面上改变的内容也抓下来,q以黄色高(sh)标记Q让|页的暗操作彻底成为历双Ӏ?/p> <p>利用Inspect(g)查功能,我们q可以用鼠标在页面中直接选择一些区块,查看相应的HTML源代码和CSS样式表,真正的做到所见即所得,如果你用了(jin)外部~辑器修改了(jin)当前|页Q可以点击Firebug的reload囄重新载入|页Q它?x)l跟t你之前用Inspect选中的区块,方便调试?/p> <p>?:QHTML查看?br /> <img alt="HTML查看? src="http://www.ooso.net/wp-content/uploads/2007/firebug3.gif" /></p> <h3>CSS调试</h3> <p>Firebug的CSS调试器是专ؓ(f)|页设计师们量n定做的?/p> <p>如今的网设计言必称div+cssQ如果你是用table套出来的HTML面Q就得按q规矩重构一遍,否则昑־你不够时髦!用div做出来的面的确能精HTML代码QHTML标签减肥的结果就是CSS样式表的~写成了(jin)面制作的重头戏。Firebug的CSS查看器不仅自下向上列出每一个CSS样式表的从属l承关系Q还列出?jin)每一个样式在哪个样式文g中定义。你可以在这个查看器中直接添加、修攏V删除一些CSS样式表属性,q在当前面中直接看C改后的结果?/p> <p>一个典型的应用是面中的一个区块位|显得有些不太恰当,它需要挪动几个象素。这时候用CSS调试工具可以L~辑它的位置——你可以Ҏ(gu)需要随意挪动象素?br /> 如图4中正在修改一个区块的背景艌Ӏ?/p> <p>提示Q如果你正在学习(fn)CSS样式表的应用Q但是总记不住常用的样式表有哪些|可以试在CSS调试器中选中一个样式表属性,然后用上下方向键来改变它的|它会(x)把可能的g个个遍历l你看?/p> <p>?: CSS查看器,能够直接修改样式?br /> <img alt="?: CSS查看器,能够直接修改样式? src="http://www.ooso.net/wp-content/uploads/2007/firebug4.gif" /></p> <h3>可视化的CSS标</h3> <p>我们可以利用Firebug来查看页面中某一区块的CSS样式表,如果q一步展开右侧Layout tab的话Q它?x)以标尺的Ş式将当前区块占用的面U清楚地标识出来Q精到象素Q更让h惊讶的是Q你能够在这个可视化的界面中直接修改各象素的|面上区块的位置׃(x)随改动而变化。在面中某些元素出现错位或者面U超出预料值时Q该功能能够提供有效的帮助,你可以籍此分析offset、margin、padding、size之间的关p,从而找?gu)决问题的办法?/p> <p>?QFirebug中的CSS标尺<br /> <img style="width: 513px; height: 431px" height="431" alt="?QFirebug中的CSS标尺" src="http://www.ooso.net/wp-content/uploads/2007/firebug5.gif" width="513" /></p> <h3>|络状况监视?/h3> <p>也许有一天,你的老板或者客hCQ抱怨你制作的网速度奇慢Q你该如何应对?你或怼(x)说这可能是网l问题,或者是?sh)脑配置问题Q或者是E序太慢Q或者直说是他们的h品问题?不管怎么_(d)最后你可能被要求去解决q个有多U可能的问题?/p> <p>|络状况监视器能帮你解决q个手问题。Firebug的网l监视器同样是功能强大的Q它能将面中的CSS、javascript以及(qing)|页中引用的囄载入所消耗的旉以矩状图呈现出来Q也许在q里你能一把揪出拖慢了(jin)你的|页的元Ӟq而对|页q行调优Q最后老板满意客户Ƣ喜Q你的饭也因此而牢固?/p> <p>|络监视器还有一些其它细节功能,比如预览囄Q查看每一个外部文件甚x(chng)xmlHttpRequestsh的http头等{?/p> <p>?Q网l状늛视器<br /> <img style="width: 483px; height: 72px" height="72" alt="?Q网l状늛视器" src="http://www.ooso.net/wp-content/uploads/2007/firebug6.gif" width="483" /></p> <h3>Javascript调试?/h3> <p>q是一个很不错的javascript脚本调试器,占用I间不大Q但是单步调试、设|断炏V变量查看窗口一个不。正所谓麻雀虽小Q五脏俱全?/p> <p>如果你有一个网站已l徏成,然而它的javascript有性能上的问题或者不是太完美Q可以通过面板上的Profile来统计每D脚本运行的旉Q查看到底是哪些语句执行旉q长Q一步步排除问题?/p> <p>?Qjavascript调试?br /> <img style="width: 501px; height: 274px" height="274" alt="?Qjavascript调试? src="http://www.ooso.net/wp-content/uploads/2007/firebug7.gif" width="501" /></p> <h3>DOM查看?/h3> <p>DOM(Document Object Model)里头包含?jin)大量的Object以及(qing)函数、事Ӟ在从前,你要想从中查到需要的内容Q绝非易事,q好比你M(jin)一个巨大的图书馆,惌扑ֈ几本名字不太切的小书,众多的选择?x)让你无所适从。而用Firebug的DOM查看器却能方便地览DOM的内部结构,帮助你快速定位DOM对象。双M个DOM对象Q就能够~辑它的变量或|~辑的同Ӟ你可能会(x)发现它还有自动完成功能,当你输入document.get之后Q按下tab键就能补齐ؓ(f)document.getElementByIdQ非常方ѝ如果你认ؓ(f)补齐得不够理惻I按下shift+tab又会(x)恢复原状。用?jin)Firebug的DOM查看器,你的javascript从此扑ֈ?jin)驱使的对象QW(xu)eb开发也许就成了(jin)一件乐事?/p> <p>?: Dom查看?br /> <img style="width: 521px; height: 171px" height="171" alt="?: Dom查看? src="http://www.ooso.net/wp-content/uploads/2007/firebug8.gif" width="521" /></p> <h3>结</h3> <p>Firebug插g提供?jin)一整套web开发所必需的工兗从HTML的编写,到CSS样式表的化调优Q以?qing)用javascript脚本开发,亦或是Ajax应用QFirebug插g都会(x)成ؓ(f)你的得力助手。所谓工Ʋ善其事Q必先利其器。在Web2.0的时代,a必称AjaxQ动辄就是用户体验提升,如果把Firebug工具用好Q必能让你如虎添|HTML、CSS、javascript整理得服服帖帖,从此成ؓ(f)web开发中的专家人物?/p> <h3>?/h3> <p>Firebug的中文含义是萤火虫,作者是Joe HewittQ官方网?http://www.getfirebug.com<br /> Firefox亦即火狐览器,是近q来撼动IE览器市(jng)场占有率的一支强大力量,要不是它的出玎ͼ我想有生之年说不定也看不到IE 7的发布了(jin)Q官方网?http://www.firefox.com</p> 引用:http://www.ooso.net/index.php/archives/294 <img src ="http://www.aygfsteel.com/aoneany/aggbug/198592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2008-05-05 23:05 <a href="http://www.aygfsteel.com/aoneany/articles/198592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript~辑器和调试工具http://www.aygfsteel.com/aoneany/articles/198591.html沙漠中的?/dc:creator>沙漠中的?/author>Mon, 05 May 2008 15:03:00 GMThttp://www.aygfsteel.com/aoneany/articles/198591.htmlhttp://www.aygfsteel.com/aoneany/comments/198591.htmlhttp://www.aygfsteel.com/aoneany/articles/198591.html#Feedback1http://www.aygfsteel.com/aoneany/comments/commentRss/198591.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/198591.html         最q在做javascript开发,x(chng)一个比较好的javasctipt~辑器,在网上看C(jin)?st JavaScript Editor 的评价不错,集成代码自动弹出昄Q验证错误功能。可以说是最好的一个javascript~辑器了(jin)Q于是把它下下来Q用h实q(sh)错,对于javascrtipt初学者还是javasctipt工程师,用这个工兗?br />

          但是他对(g)错方面没有myesclipse的好Q对于有一些警告和错误它不能提C出?/p>

          对于javasctipt调试工具Q也有好几种可选择的方?׃机器比较慢,我采用的是firefox+firebug来调试,在网上找?jin)一介l的文gQ等下把它帖出来Q开?Net的h都知道,vs是一个很不错的调试javasctipt工具Q我以前也一直用q个来调试javasctipt,不过专门用来调试javasctiptQ可以说是大材小用了(jin)



]]>
Dom-Drag学习(fn)http://www.aygfsteel.com/aoneany/articles/195582.html沙漠中的?/dc:creator>沙漠中的?/author>Thu, 24 Apr 2008 06:41:00 GMThttp://www.aygfsteel.com/aoneany/articles/195582.htmlhttp://www.aygfsteel.com/aoneany/comments/195582.htmlhttp://www.aygfsteel.com/aoneany/articles/195582.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/195582.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/195582.html阅读全文

]]>
JavaScript之实现私有属性、像C++和Java一h持基于类的承方法之例子http://www.aygfsteel.com/aoneany/articles/195574.html沙漠中的?/dc:creator>沙漠中的?/author>Thu, 24 Apr 2008 06:29:00 GMThttp://www.aygfsteel.com/aoneany/articles/195574.htmlhttp://www.aygfsteel.com/aoneany/comments/195574.htmlhttp://www.aygfsteel.com/aoneany/articles/195574.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/195574.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/195574.html阅读全文

]]>
JavaScript中基于类的?/title><link>http://www.aygfsteel.com/aoneany/articles/195569.html</link><dc:creator>沙漠中的?/dc:creator><author>沙漠中的?/author><pubDate>Thu, 24 Apr 2008 06:21:00 GMT</pubDate><guid>http://www.aygfsteel.com/aoneany/articles/195569.html</guid><wfw:comment>http://www.aygfsteel.com/aoneany/comments/195569.html</wfw:comment><comments>http://www.aygfsteel.com/aoneany/articles/195569.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/aoneany/comments/commentRss/195569.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/aoneany/services/trackbacks/195569.html</trackback:ping><description><![CDATA[<p><font style="background-color: #c7edcc">JavaScript中基于prototype的承机制可以很好地工作Q但是对于一些已l习(fn)惯于C++和Java{语a中基于类的承机制的人来_(d)JavaScript的prototypel承机制不是一U自然的~程Ҏ(gu)。如果你不想用基于prototype的承,而想用一U基于类的承方法,那就l箋(hu)Md?br /> Netscape的Bob Clary[4]也提Z(jin)一个方法,它可以一个对象用一个通用的脚本从另一个对象承属性和函数。这个脚本只是将“?#8221;对象的属性和函数单地复制?#8220;?#8221;对象。ؓ(f)此,我们说明如何对脚本E加修改Q从而只是将子对象中不存在的属性和函数复制到子对象Q这样一来,子对象中的函数就能覆盖父对象的函数。在两个对象之间创徏l承关系的通用函数如下Q?br /> function createInheritance(parent, child) {<br />     var property;<br />     for(property in parent) {<br />         if(!child[property]) {<br />             child[property] = parent[property];<br />         }<br />     }<br /> }<br /> createInheritance函数有两个参敎ͼ父对象和子对象。这个函数只是P代处理父对象的所有成员(成员是属性或函数Q,如果某个成员在子对象中不存在Q则复制到子对象?br /> 使用createInheritance函数相当单:(x)首先创徏子对象的一个实例,然后使用createInheritance函数Qؓ(f)它传递子对象以及(qing)父对象的一个实例,如下Q?br /> var child = new Child();<br /> createInheritance(new Parent(), child);<br /> 父对象中有而子对象中没有的所有属性和Ҏ(gu)复制到子对象?/font><br /> </p> <p>引用:<a target="_blank">http://book.csdn.net/bookfiles/11/100117056.shtml</a></p> <img src ="http://www.aygfsteel.com/aoneany/aggbug/195569.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/aoneany/" target="_blank">沙漠中的?/a> 2008-04-24 14:21 <a href="http://www.aygfsteel.com/aoneany/articles/195569.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaScriptU有属性和使用JavaScript的信息隐?http://www.aygfsteel.com/aoneany/articles/195564.html沙漠中的?/dc:creator>沙漠中的?/author>Thu, 24 Apr 2008 06:04:00 GMThttp://www.aygfsteel.com/aoneany/articles/195564.htmlhttp://www.aygfsteel.com/aoneany/comments/195564.htmlhttp://www.aygfsteel.com/aoneany/articles/195564.html#Feedback0http://www.aygfsteel.com/aoneany/comments/commentRss/195564.htmlhttp://www.aygfsteel.com/aoneany/services/trackbacks/195564.html        铁杆的面向对象设计支持者会(x)注意刎ͼ当用prototypeҎ(gu)向JavaScript对象增加属性和函数Ӟ所增加的属性和函数都是公用的,所有其他对象都能访问。对于函数来_(d)q通常没有问题Q因为大多数函数都确实应当提供给外部客户。但是对于属性,面向对象设计的支持者就?x)指出,公有属性违反了(jin)信息隐藏的概念,对象的属性应当是U有的,因此外部客户不能直接讉K。外部客户只能通过公用可用的函数来讉K对象的私有属性?/font>

对于JavaScriptQ同h可能创徏外部客户不能讉K的私有属性,而只能通过对象的(公用Q方法来讉KQ但q一点很有人知道。Douglas Crockford[3]提出?jin)一U在JavaScript中创建私有属性的Ҏ(gu)。这U方法非常简单,ȝ如下Q?/font>

l    U有属性可以在构造函C使用var关键字定义?/font>

l    U有属性只能由Ҏ(gu)函数Qprivileged functionQ公用访问。特权函数就是在构造函C使用this关键字定义的函数。外部客户可以访问特权函敎ͼ而且Ҏ(gu)函数可以讉K对象的私有属性?/font>

下面来考虑前一个示例中的VehiclecR假设你惌wheelCount和curbWeightIn- Pounds属性是U有的,q只能通过公用Ҏ(gu)讉K。新的Vehicle对象如代码清?-4所C?/font>

代码清单5-4  重写后的Vehicle对象

function Vehicle() {

    
var wheelCount = 4;

    
var curbWeightInPounds = 4000;

    
this.getWheelCount = function() {
        
return wheelCount;
    }


    
this.setWheelCount = function(count) {
        wheelCount 
= count;
    }


    
this.getCurbWeightInPounds = function() {
        
return curbWeightInPounds;
    }


    
this.setCurbWeightInPounds = function(weight) {
        curbWeightInPounds 
= weight;
    }


    
this.refuel = function() {
        
return "Refueling Vehicle with regular 87 octane gasoline";
    }


    
this.mainTasks = function() {
        
return "Driving to work, school, and the grocery store";
    }

}

 

注意QwheelCount和curbWeightInPounds属性都在构造函C使用var关键字定义,q就使得q两个属性是U有属性。属性不再是公用的,如果想通过点记法访问wheelCount属性的|如下Q?/font>

var numberOfWheels = vehicle.wheelCount;

׃(x)q回undefinedQ而不是wheelCount实际的倹{?/font>

׃属性现在是U有的,因此需要提供能讉Kq些属性的公用函数。getWheelCount、setWheelCount、getCurbWeightInPounds和setCurbWeightInPounds函数是作此使用的。现在Vehicle对象可以保证只能通过公用函数讉KU有属性,因此满?jin)信息隐藏?/font>


 

引用:http://book.csdn.net/bookfiles/11/100117056.shtml



]]>
վ֩ģ壺 ƽ| ̩| | Ǧɽ| Ͱ| ĵ| | ̫| ׼| ɽ| | | | | ˮ| | лͨ| Դ| żҸ| ƽ| | Ԫ| Զ| | | ¡| | | ɽ| ƽ| | ƽ| Ϋ| | «ɽ| ƾ| ׿| ;| ɳ| Զ| |