﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-280211429-文章分类-js</title><link>http://www.blogjava.net/280211429/category/13193.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 05:00:41 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 05:00:41 GMT</pubDate><ttl>60</ttl><item><title>js关键字总结</title><link>http://www.blogjava.net/280211429/articles/59161.html</link><dc:creator>国强</dc:creator><author>国强</author><pubDate>Thu, 20 Jul 2006 04:28:00 GMT</pubDate><guid>http://www.blogjava.net/280211429/articles/59161.html</guid><wfw:comment>http://www.blogjava.net/280211429/comments/59161.html</wfw:comment><comments>http://www.blogjava.net/280211429/articles/59161.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/280211429/comments/commentRss/59161.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/280211429/services/trackbacks/59161.html</trackback:ping><description><![CDATA[
		<div id="ContentBody" style="PADDING-RIGHT: 10px; DISPLAY: block; PADDING-LEFT: 10px; PADDING-BOTTOM: 10px; PADDING-TOP: 10px">1.document.write(""); 输出语句<br />2.JS中的注释为//<br />3.传统的HTML文档顺序是:document-&gt;html-&gt;(head,body)<br />4.一个浏览器窗口中的DOM顺序是:window-&gt;(navigator,screen,history,location,document)<br />5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value)<br />6.一个小写转大写的JS: document.getElementById("output").value = <br />document.getElementById("input").value.toUpperCase();<br />7.JS中的值类型:String,Number,Boolean,Null,Object,Function<br />8.JS中的字符型转换成数值型:parseInt(),parseFloat()<br />9.JS中的数字转换成字符型:(""+变量)<br />10.JS中的取字符串长度是:(length)<br />11.JS中的字符与字符相连接使用+号.<br />12.JS中的比较操作符有:==等于,!=不等于,&gt;,&gt;=,&lt;.&lt;=<br />13.JS中声明变量使用:var来进行声明<br />14.JS中的判断语句结构:if(condition){}else{}<br />15.JS中的循环结构:for([initial expression];[condition];[upadte expression]) {inside loop}<br />16.循环中止的命令是:break<br />17.JS中的函数定义:function functionName([parameter],...){statement[s]}<br />18.当文件中出现多个form表单时.可以用document.forms[0],document.forms[1]来代替.<br />19.窗口:打开窗口window.open(), 关闭一个窗口:window.close(), 窗口本身:self<br />20.状态栏的设置:window.status="字符";<br />21.弹出提示信息:window.alert("字符");<br />22.弹出确认框:window.confirm();<br />23.弹出输入提示框:window.prompt();<br />24.指定当前显示链接的位置:window.location.href="URL"<br />25.取出窗体中的所有表单的数量:document.forms.length<br />26.关闭文档的输出流:document.close();<br />27.字符串追加连接符:+=<br />28.创建一个文档元素:document.createElement(),document.createTextNode()<br />29.得到元素的方法:document.getElementById()<br />30.设置表单中所有文本型的成员的值为空:<br />var form = window.document.forms[0]<br />for (var i = 0; i&lt;form.elements.length;i++){<br />    if (form.elements.type == "text"){<br />        form.elements.value = "";<br />    }<br />}<br />31.复选按钮在JS中判断是否选中:document.forms[0].checkThis.checked (checked属性代表为是否选中返回TRUE或FALSE)<br />32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度document.forms[0].groupName.length<br />33.单选按钮组判断是否被选中也是用checked.<br />34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有时用下拉列表框名称加上.selectedIndex来确定被选中的值)<br />35.字符串的定义:var myString = new String("This is lightsword");<br />36.字符串转成大写:string.toUpperCase(); 字符串转成小写:string.toLowerCase();<br />37.返回字符串2在字符串1中出现的位置:String1.indexOf("String2")!=-1则说明没找到.<br />38.取字符串中指定位置的一个字符:StringA.charAt(9);<br />39.取出字符串中指定起点和终点的子字符串:stringA.substring(2,6);<br />40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函数,Math.floor(Math.random()*(n+1))返回随机数<br />41.定义日期型变量:var today = new Date();<br />42.日期函数列表:dateObj.getTime()得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,dateObj.getHours()得到小时,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTime(value)设置时间,dateObj.setYear(val)设置年,dateObj.setMonth(val)设置月,dateObj.setDate(val)设置日,dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,dateObj.setSeconds(val)设置秒  [注意:此日期时间从0开始计]<br />43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName<br />44.parent代表父亲对象,top代表最顶端对象<br />45.打开子窗口的父窗口为:opener<br />46.表示当前所属的位置:this<br />47.当在超链接中调用JS函数时用:(javascript :)来开头后面加函数名<br />48.在老的浏览器中不执行此JS:&lt;!--      //--&gt;<br />49.引用一个文件式的JS:&lt;script type="text/javascript" src="aaa.js"&gt;&lt;/script&gt;<br />50.指定在不支持脚本的浏览器显示的HTML:&lt;noscript&gt;&lt;/noscript&gt;<br />51.当超链和onCLICK事件都有时,则老版本的浏览器转向a.html,否则转向b.html.例:&lt;a href="a.html" onclick="location.href='b.html';return false"&gt;dfsadf&lt;/a&gt;<br />52.JS的内建对象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,<br />ReferenceError,RegExp,String,SyntaxError,TypeError,URIError<br />53.JS中的换行:\n<br />54.窗口全屏大小:&lt;script&gt;function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}<br />window.maximize=fullScreen;&lt;/script&gt;<br />55.JS中的all代表其下层的全部元素<br />56.JS中的焦点顺序:document.getElementByid("表单元素").tabIndex = 1<br />57.innerHTML的值是表单元素的值:如&lt;p id="para"&gt;"how are &lt;em&gt;you&lt;/em&gt;"&lt;/p&gt;,则innerHTML的值就是:how are &lt;em&gt;you&lt;/em&gt;<br />58.innerTEXT的值和上面的一样,只不过不会把&lt;em&gt;这种标记显示出来.<br />59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态.<br />60.isDisabled判断是否为禁止状态.disabled设置禁止状态<br />61.length取得长度,返回整型数值<br />62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc<br />63.window.focus()使当前的窗口在所有窗口之前.<br />64.blur()指失去焦点.与FOCUS()相反.<br />65.select()指元素为选中状态.<br />66.防止用户对文本框中输入文本:onfocus="this.blur()"<br />67.取出该元素在页面中出现的数量:document.all.tags("div(或其它HTML标记符)").length<br />68.JS中分为两种窗体输出:模态和非模态.window.showModaldialog(),window.showModeless()<br />69.状态栏文字的设置:window.status='文字',默认的状态栏文字设置:window.defaultStatus = '文字.';<br />70.添加到收藏夹:external.AddFavorite("http://www.dannyg.com";,"jaskdlf");<br />71.JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.onerror = handleError;<br />72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续.<br />73.JS中的self指的是当前的窗口<br />74.JS中状态栏显示内容:window.status="内容"<br />75.JS中的top指的是框架集中最顶层的框架<br />76.JS中关闭当前的窗口:window.close();<br />77.JS中提出是否确认的框:if(confirm("Are you sure?")){alert("ok");}else{alert("Not Ok");}<br />78.JS中的窗口重定向:window.navigate("http://www.sina.com.cn";);<br />79.JS中的打印:window.print()<br />80.JS中的提示输入框:window.prompt("message","defaultReply");<br />81.JS中的窗口滚动条:window.scroll(x,y)<br />82.JS中的窗口滚动到位置:window.scrollby<br />83.JS中设置时间间隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeout<br />84.JS中的模态显示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]);<br />85.JS中的退出之前使用的句柄:function verifyClose()<br />{event.returnValue="we really like you and hope you will stay longer.";}} <br /> window.onbeforeunload=verifyClose;<br />86.当窗体第一次调用时使用的文件句柄:onload()<br />87.当窗体关闭时调用的文件句柄:onunload()<br />88.window.location的属性: protocol(http:),hostname(www.example.com),port(80),host(www.example.com:80),pathname("/a/a.html"),hash("#giantGizmo",指跳转到相应的锚记),href(全部的信息)<br />89.window.location.reload()刷新当前页面.<br />90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL)<br />91.document.write()不换行的输出,document.writeln()换行输出<br />92.document.body.noWrap=true;防止链接文字折行.<br />93.变量名.charAt(第几位),取该变量的第几位的字符.<br />94."abc".charCodeAt(第几个),返回第几个字符的ASCii码值.<br />95.字符串连接:string.concat(string2),或用+=进行连接<br />96.变量.indexOf("字符",起始位置),返回第一个出现的位置(从0开始计算)<br />97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置.<br />98.string.match(regExpression),判断字符是否匹配.<br />99.string.replace(regExpression,replaceString)替换现有字符串.<br />100.string.split(分隔符)返回一个数组存储值.<br />101.string.substr(start[,length])取从第几位到指定长度的字符串.<br />102.string.toLowerCase()使字符串全部变为小写.<br />103.string.toUpperCase()使全部字符变为大写.<br />104.parseInt(string[,radix(代表进制)])强制转换成整型.<br />105.parseFloat(string[,radix])强制转换成浮点型.<br />106.isNaN(变量):测试是否为数值型.<br />107.定义常量的关键字:const,定义变量的关键字:var </div>
<img src ="http://www.blogjava.net/280211429/aggbug/59161.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/280211429/" target="_blank">国强</a> 2006-07-20 12:28 <a href="http://www.blogjava.net/280211429/articles/59161.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让我们的Javascript兼容多种浏览器 </title><link>http://www.blogjava.net/280211429/articles/58947.html</link><dc:creator>国强</dc:creator><author>国强</author><pubDate>Wed, 19 Jul 2006 03:25:00 GMT</pubDate><guid>http://www.blogjava.net/280211429/articles/58947.html</guid><wfw:comment>http://www.blogjava.net/280211429/comments/58947.html</wfw:comment><comments>http://www.blogjava.net/280211429/articles/58947.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/280211429/comments/commentRss/58947.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/280211429/services/trackbacks/58947.html</trackback:ping><description><![CDATA[随着以Firefox为代表的第三方浏览器的兴起，我们做的网站也不能再JUST IE了，如果把原来的一些Javascript代码放到IE以外的浏览器的话，往往都不能正常运行或出错，所以这里介绍一下怎么改进我们的JS，让它能更加规范，更加具有兼容性。<br /><br />示例代码：<br />&lt;body&gt;&lt;table border="1" cellspacing="0" cellpadding="0" id="apple" &gt; &lt;tbody&gt;<br />  &lt;tr&gt;     &lt;td id="banana" style="color:red" &gt;不吃苹果&lt;/td&gt;  &lt;/tr&gt;<br /> &lt;/tbody&gt;&lt;/table&gt;&lt;/body&gt;<br />尽量采用W3C DOM 的写法<br />以前访问对象可能是：<br />document.all.apple 或者 apple<br />现在应该采用：<br />document.getElementById("apple") 以ID来访问对象，且一个ID在页面中必须是唯一的<br />document.getElementsByTagName("div")[0] 以标签名来访问对象<br />原来设置对象的属性可能是：<br />document.all.apple.width=100 或 apple.width=100<br />现在应该采用：<br />document.getElementById("apple").setAttribute("width","100")<br />document.getElementsByTagName("div")[0].setAttribute("width","100")<br />访问对象的属性则采用：<br />document.getElementById("apple").getAttribute("width")<br />document.getElementsByTagName("div")[0].getAttribute("width")<br />W3C DOM在IE下的一些限制<br />因为起先的IE占据整个浏览器95%的份额，没有竞争压力，所以这位老大就硬是要玩点另类，不完全按WEB标准来搞。<br /><br />在IE下不能正确使用setAttribute来设置对象的style、class以及事件响应属性，<br />因此我还得按原来的点记法来访问和设置，以达到兼容各种浏览器的效果,如：<br />document.getElementById("banana").class<br />document.getElementById("banana").style.color<br />document.getElementById("banana").onclick<br />document.getElementById("banana").class="fruit"<br />document.getElementById("banana").style.color="blue"<br />document.getElementById("banana").onclick= function (){alert("我是香蕉")}<br />关于Firefox下的onload问题<br />function over(){<br /> alert("页面加载完毕")<br />}<br /><br />正常情况下，我们赋与onload响应函数是：<br />document.body.onload= over<br />但是在Firefox下这样无法执行，<br />所以我们都都采用下面这种形式：<br />window.onload=over<br />关于IE下TABLE无法插入新行的问题<br />IE下TABLE无论是用innerHTML还是appendChild插入&lt;tr&gt;都没有效果，而其他浏览器却显示正常。解决他的方法是，将&lt;tr&gt;加到TABLE的&lt;tbody&gt;元素中，如下面所示：<br /><br />var row = document.createElement("tr");<br />var cell = document.createElement("td");<br />var cell_text = document.createTextNode("香蕉不吃苹果");<br />cell.appendChild(cell_text);<br />row.appendChild(cell);<br />document.getElementsByTagName("tbody")[0].appendChild(row);<br /><img src ="http://www.blogjava.net/280211429/aggbug/58947.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/280211429/" target="_blank">国强</a> 2006-07-19 11:25 <a href="http://www.blogjava.net/280211429/articles/58947.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaScript 5：窗口和框架 </title><link>http://www.blogjava.net/280211429/articles/58688.html</link><dc:creator>国强</dc:creator><author>国强</author><pubDate>Tue, 18 Jul 2006 01:54:00 GMT</pubDate><guid>http://www.blogjava.net/280211429/articles/58688.html</guid><wfw:comment>http://www.blogjava.net/280211429/comments/58688.html</wfw:comment><comments>http://www.blogjava.net/280211429/articles/58688.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/280211429/comments/commentRss/58688.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/280211429/services/trackbacks/58688.html</trackback:ping><description><![CDATA[
		<div class="postcontent">
				<div style="FONT-SIZE: 14px; WIDTH: 95%; LINE-HEIGHT: 155%">
						<span id="zoom">54 改变浏览器状态栏文字提示<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">status </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">“A </span><span style="COLOR: #006600">new </span><span style="COLOR: #0000cc">status message”</span><span style="COLOR: #006600">;<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />55 弹出确认提示框<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li>var </li></span><span style="COLOR: #0000cc">userChoice </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">confirm</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“Click OK </span><span style="COLOR: #006600">or </span><span style="COLOR: #0000cc">Cancel”</span><span style="COLOR: #006600">);<br /><li>if (</li></span><span style="COLOR: #0000cc">userChoice</span><span style="COLOR: #006600">) { <br /><li></li></span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">write</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“You chose OK”</span><span style="COLOR: #006600">);<br /><li> } else { <br /></li><li></li></span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">write</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“You chose Cancel”</span><span style="COLOR: #006600">);<br /><li> }<br /></li><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />56 提示输入<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li>var </li></span><span style="COLOR: #0000cc">userName </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">prompt</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“Please Enter Your Name”</span><span style="COLOR: #006600">,</span><span style="COLOR: #0000cc">”Enter Your Name Here”</span><span style="COLOR: #006600">);<br /><li></li></span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">write</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“Your Name is “ </span><span style="COLOR: #006600">+ </span><span style="COLOR: #0000cc">userName</span><span style="COLOR: #006600">);<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />57 打开一个新窗口<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #ff9900">//打开一个名称为myNewWindow的浏览器新窗口<br /><li></li></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“http</span><span style="COLOR: #006600">:</span><span style="COLOR: #ff9900">//www.liu21st.com/”,”myNewWindow”);<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />58 设置新窗口的大小<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“http</span><span style="COLOR: #006600">:</span><span style="COLOR: #ff9900">//www.liu21st.com/”,”myNewWindow”,'height=300,width=300');<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />59 设置新窗口的位置<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“http</span><span style="COLOR: #006600">:</span><span style="COLOR: #ff9900">//www.liu21st.com/”,”myNewWindow”,'height=300,width=300,left=200,screenX=200,top=100,screenY=100');<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />60 是否显示工具栏和滚动栏<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“http</span><span style="COLOR: #006600">:</span></span></li></ol></code><br /></div></div><br />61 是否可以缩放新窗口的大小<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #cc0000">'http://www.liu21st.com/' </span><span style="COLOR: #006600">, </span><span style="COLOR: #cc0000">'myNewWindow'</span><span style="COLOR: #006600">, </span><span style="COLOR: #cc0000">'resizable=yes' </span><span style="COLOR: #006600">);</span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />62 加载一个新的文档到当前窗口<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">a href</span><span style="COLOR: #006600">=</span><span style="COLOR: #cc0000">'#' </span><span style="COLOR: #0000cc">onClick</span><span style="COLOR: #006600">=</span><span style="COLOR: #cc0000">'document.location = '</span><span style="COLOR: #0000cc">125a</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html</span><span style="COLOR: #cc0000">';' </span><span style="COLOR: #006600">&gt;</span><span style="COLOR: #0000cc">Open </span><span style="COLOR: #006600">New </span><span style="COLOR: #0000cc">Document</span><span style="COLOR: #006600">&lt;/</span><span style="COLOR: #0000cc">a</span><span style="COLOR: #006600">&gt;</span></span></li></ol></code><br /></div></div><br />63 设置页面的滚动位置<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li>if (</li></span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">all</span><span style="COLOR: #006600">) { </span><span style="COLOR: #ff9900">//如果是IE浏览器则使用scrollTop属性<br /><li></li></span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">body</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">scrollTop </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">200</span><span style="COLOR: #006600">;<br /><li> } else { </li></span><span style="COLOR: #ff9900">//如果是NetScape浏览器则使用pageYOffset属性<br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">pageYOffset </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">200</span><span style="COLOR: #006600">;<br /><li> }</li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />64 在IE中打开全屏窗口<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">a href</span><span style="COLOR: #006600">=</span><span style="COLOR: #cc0000">'#'  </span><span style="COLOR: #0000cc">onClick</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #cc0000">'http://www.juxta.com/'</span><span style="COLOR: #006600">,</span><span style="COLOR: #cc0000">'newWindow'</span><span style="COLOR: #006600">,</span><span style="COLOR: #cc0000">'fullScreen=yes'</span><span style="COLOR: #006600">);</span><span style="COLOR: #0000cc">”</span><span style="COLOR: #006600">&gt;</span><span style="COLOR: #0000cc">Open a full</span><span style="COLOR: #006600">-</span><span style="COLOR: #0000cc">screen window</span><span style="COLOR: #006600">&lt;/</span><span style="COLOR: #0000cc">a</span><span style="COLOR: #006600">&gt;</span></span></li></ol></code><br /></div></div><br />65 新窗口和父窗口的操作<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #ff9900">//定义新窗口<br /><li></li></span><span style="COLOR: #006600">var </span><span style="COLOR: #0000cc">newWindow </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“128a</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html”</span><span style="COLOR: #006600">,</span><span style="COLOR: #0000cc">”newWindow”</span><span style="COLOR: #006600">);<br /><li></li></span><span style="COLOR: #0000cc">newWindow</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">close</span><span style="COLOR: #006600">(); </span><span style="COLOR: #ff9900">//在父窗口中关闭打开的新窗口<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;<br /><li></li></span>在新窗口中关闭父窗口<br /><li>window.opener.close()</li></span></li></ol></code><br /></div></div><br />66 往新窗口中写内容<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li>var </li></span><span style="COLOR: #0000cc">newWindow </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“”</span><span style="COLOR: #006600">,</span><span style="COLOR: #0000cc">”newWindow”</span><span style="COLOR: #006600">);<br /><li></li></span><span style="COLOR: #0000cc">newWindow</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">open</span><span style="COLOR: #006600">();<br /><li></li></span><span style="COLOR: #0000cc">newWindow</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">write</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“This is a </span><span style="COLOR: #006600">new </span><span style="COLOR: #0000cc">window”</span><span style="COLOR: #006600">);<br /><li></li></span><span style="COLOR: #0000cc">newWIndow</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">close</span><span style="COLOR: #006600">();<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;</span></span></li></ol></code><br /></div></div><br />67 加载页面到框架页面<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">frameset cols</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”50</span><span style="COLOR: #006600">%,*</span><span style="COLOR: #0000cc">”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;</li></span><span style="COLOR: #0000cc">frame name</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”frame1” src</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”135a</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;</li></span><span style="COLOR: #0000cc">frame name</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”frame2” src</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”about</span><span style="COLOR: #006600">:</span><span style="COLOR: #0000cc">blank”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;/</li></span><span style="COLOR: #0000cc">frameset</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">在frame1中加载frame2中的页面<br /><li>parent</li></span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">frame2</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">document</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">location </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">“135b</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html”</span><span style="COLOR: #006600">;</span></span></li></ol></code><br /></div></div><br />68 在框架页面之间共享脚本<br />如果在frame1中html文件中有个脚本<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">function </span><span style="COLOR: #0000cc">doAlert</span><span style="COLOR: #006600">() { <br /><li></li></span><span style="COLOR: #0000cc">window</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">alert</span><span style="COLOR: #006600">(</span><span style="COLOR: #0000cc">“Frame 1 is loaded”</span><span style="COLOR: #006600">);<br /><li> }</li></span></span></li></ol></code><br /></div></div>那么在frame2中可以如此调用该方法<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">body onLoad</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”parent</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">frame1</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">doAlert</span><span style="COLOR: #006600">();</span><span style="COLOR: #0000cc">”</span><span style="COLOR: #006600">&gt;<br /><li></li></span><span style="COLOR: #0000cc">This is frame 2.<br /><li></li></span><span style="COLOR: #006600">&lt;/</span><span style="COLOR: #0000cc">body</span><span style="COLOR: #006600">&gt;</span></span></li></ol></code><br /></div></div><br />69 数据公用<br />可以在框架页面定义数据项，使得该数据可以被多个框架中的页面公用<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">script language</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”JavaScript”</span><span style="COLOR: #006600">&gt;<br /><li>var </li></span><span style="COLOR: #0000cc">persistentVariable </span><span style="COLOR: #006600">= </span><span style="COLOR: #0000cc">“This is a persistent value”</span><span style="COLOR: #006600">;<br /><li></li></span><span style="COLOR: #0000cc">&lt;/script&gt;<br /><li></li></span>&lt;frameset cols=”50%,*”&gt;<br /><li>&lt;frame name=”frame1” src=”138a.html”&gt;<br /></li><li>&lt;frame name=”frame2” src=”138b.html”&gt;<br /></li><li>&lt;/frameset&gt;</li></span></li></ol></code><br /></div></div><br />这样在frame1和frame2中都可以使用变量persistentVariable <br />70 框架代码库<br />根据以上的一些思路，我们可以使用一个隐藏的框架页面来作为整个框架集的代码库<br /><div id="code"><div style="MARGIN-LEFT: 5pt"><code><ol><li><span style="COLOR: #000000"><span style="COLOR: #0000cc"></span><span style="COLOR: #006600">&lt;</span><span style="COLOR: #0000cc">frameset cols</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”0</span><span style="COLOR: #006600">,</span><span style="COLOR: #0000cc">50</span><span style="COLOR: #006600">%,*</span><span style="COLOR: #0000cc">”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;</li></span><span style="COLOR: #0000cc">frame name</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”codeFrame” src</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”140code</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;</li></span><span style="COLOR: #0000cc">frame name</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”frame1” src</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”140a</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;</li></span><span style="COLOR: #0000cc">frame name</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”frame2” src</span><span style="COLOR: #006600">=</span><span style="COLOR: #0000cc">”140b</span><span style="COLOR: #006600">.</span><span style="COLOR: #0000cc">html”</span><span style="COLOR: #006600">&gt;<br /><li>&lt;/</li></span><span style="COLOR: #0000cc">frameset</span><span style="COLOR: #006600">&gt;</span></span></li></ol></code></div></div></span>
				</div>
		</div>
<img src ="http://www.blogjava.net/280211429/aggbug/58688.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/280211429/" target="_blank">国强</a> 2006-07-18 09:54 <a href="http://www.blogjava.net/280211429/articles/58688.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaScript实际应用：innerHTMl和确认提示的使用 </title><link>http://www.blogjava.net/280211429/articles/58687.html</link><dc:creator>国强</dc:creator><author>国强</author><pubDate>Tue, 18 Jul 2006 01:50:00 GMT</pubDate><guid>http://www.blogjava.net/280211429/articles/58687.html</guid><wfw:comment>http://www.blogjava.net/280211429/comments/58687.html</wfw:comment><comments>http://www.blogjava.net/280211429/articles/58687.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/280211429/comments/commentRss/58687.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/280211429/services/trackbacks/58687.html</trackback:ping><description><![CDATA[
		<h2 class="ContentAuthor"> </h2>
		<div class="Content-body" id="logPanel">　　今天开发中涉及到对一个层的信息控制，就是控制一个层中显示什么信息，查找资料才知道使用innerHTML属性来控制层的值，这个innerHTML跟表单里面的value属性有点类似，能够控制层的显示值。<br /><br />　　比如说我一个div层里本来没有值，我处罚一个事件后要显示值，那么就能够使用innerHTML属性了，其实innerHTML属性除了能控制层以外，还能控制窗口内容的所有元素，但是我没有测试过。<br /><br /><strong>（1）对div标签的控制</strong><br /><br />div标签跟span标签是不一样的，div是一个层的块，span是一行，我们下面看演示就知道区别了。先来看一段控制div的代码。<br /><br /><div class="UBBPanel"><div class="UBBTitle"><img style="MARGIN: 0px 2px -3px 0px" alt="程序代码" src="http://mysheji.com/blog/images/code.gif" /> 程序代码</div><div class="UBBContent">&lt;script language="javascript"&gt;<br />function chageDiv(number)<br />{<br />if (number == 1) {<br />document.getElementById("div1").innerHTML = "值为1";<br />}<br />if (number == 2) {<br />document.getElementById("div1").innerHTML = "值为2";<br />}<br />}<br />&lt;/script&gt;<br /><br />DIV块测试：&lt;div id="div1"&gt;默认值&lt;/div&gt;<br /><br />&lt;a href="#" onClick="chageDiv(1)"&gt;改变值为1&lt;/a&gt; <br />&lt;a href="#" onClick="chageDiv(2)"&gt;改变值为2&lt;/a&gt;<br /></div></div><br /><br />演示：<br /><div class="UBBPanel"><div class="UBBTitle"><img style="MARGIN: 0px 2px -3px 0px" src="http://mysheji.com/blog/images/html.gif" /> HTML代码</div><div class="UBBContent"><textarea id="temp17863" rows="8">&lt;script language="javascript"&gt;
function chageDiv(number)
{
 if (number == 1) {
  document.getElementById("div1").innerHTML = "值为1";
 }
 if (number == 2) {
  document.getElementById("div1").innerHTML = "值为2";
 }
}
&lt;/script&gt;

DIV块测试：&lt;div id="div1"&gt;默认值&lt;/div&gt;
&lt;a href="#" onClick="chageDiv(1)"&gt;改变值为1&lt;/a&gt; 
&lt;a href="#" onClick="chageDiv(2)"&gt;改变值为2&lt;/a&gt;</textarea><br /><input onclick="runEx('temp17863')" type="button" value="运行此代码" /><input onclick="doCopy('temp17863')" type="button" value="复制此代码" /><br />[Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</div></div><br /><br />　　运行的时候，点击“改变值为1”那么“默认值”这个内容将会被改变为“值为1”，但是注意其中的界面，就是会发现“DIV测试：”和“默认值”是两行显示的，因为DIV是按块来显示的。<br /><br /><strong>（2）对span的控制</strong><br /><br />与div类似，但是它是按照行来显示的，看下面的代码：<br /><div class="UBBPanel"><div class="UBBTitle"><img style="MARGIN: 0px 2px -3px 0px" alt="程序代码" src="http://mysheji.com/blog/images/code.gif" /> 程序代码</div><div class="UBBContent">&lt;script language="javascript"&gt;<br />function chageSpan(number)<br />{<br />if (number == 1) {<br />document.getElementById("span1").innerHTML = "值为1";<br />}<br />if (number == 2) {<br />document.getElementById("span1").innerHTML = "值为2";<br />}<br />}<br />&lt;/script&gt;<br />Span行测试：<br />&lt;span id="span1"&gt;默认值&lt;/span&gt;&lt;br&gt;<br />&lt;a href="#" onClick="chageSpan(1)"&gt;改变值为1&lt;/a&gt;<br />&lt;a href="#" onClick="chageSpan(2)"&gt;改变值为2&lt;/a&gt;</div></div><br /><br />当点击“改变值为1”的时候，“默认值”将变为“值为1”，但是“Span行测试”和“默认值”是在同一行显示的，跟DIV不一样。<br /><br />另外一个值得注意的就是，不管是div还是span，后面的名字都是以为id来定义的，不是象表单一样是使用name来定义的。<br /><br /><strong>（3）confirm确认提示框的制作</strong><br /><br />当我们要执行一个危险操作的时候，比如删除某个内容等，那么就应该给用户相应的提示来用户不容易犯错误。一般提示都是使用confirm()函数来处理的，给它提交一个参数作为显示的信息提示，那么访问的时候将弹出对话框，如果点击了“确定”那么将改函数返回true，点击了“取消”将放回false，我们针对这个特点来使用两种方法来控制用户是否执行某个操作。<br /><br />看代码：<br /><br /><div class="UBBPanel"><div class="UBBTitle"><img style="MARGIN: 0px 2px -3px 0px" alt="程序代码" src="http://mysheji.com/blog/images/code.gif" /> 程序代码</div><div class="UBBContent">&lt;script language="javascript"&gt;<br />function accessNeteasy()<br />{<br />if(confirm('你真的要访问网易新闻 ?')) {<br />location='<a href="http://calendar.eyou.eyou/" target="_blank"><font color="#808080">http://calendar.eyou.eyou</font></a>';<br />}<br />}<br />function accessSina()<br />{<br />if (confirm('你确定要访问新浪新闻 ?')) {<br />return true;<br />} else {<br />return false;<br />}<br />}<br />&lt;/script&gt;<br /><br />访问方式一：<br />&lt;a href="#" onClick="accessNeteasy()"&gt;网易新闻&lt;/a&gt;&lt;br&gt;<br />访问方式二：<br />&lt;a href="<a href="http://news.sina.com.cn/" target="_blank"><font color="#808080">http://news.sina.com.cn</font></a>" onClick="return accessSina()"&gt;新浪新闻&lt;/a&gt;</div></div><br /><br />　　我们这里建立了两个函数，一个accessNeteay，一个accessSina，就是访问网易和新浪，我们使用不同的方法，第一种就是当点了链接以后，判断如果是true的话，那么就location到指定链接，这种方法比较不具有通用型，只能针对单个的链接。第二种方法是使用返回值的形式，当确定要访问的时候返回true，不确定的时候返回false，那么这个可以针对任何链接来做，写成一个通用的信息提示，方便页面中的调用。<br /><br />以上代码都经过测试通过，可以自己再这个基础上进行扩展，写出自己需要的JavaScript代码。<br />更多小技巧建议参考<a href="http://www.blueidea.com/" target="_blank"><font color="#808080">蓝色理想</font></a>的链接：<a href="http://www.blueidea.com/tech/web/2004/2379.asp" target="_blank"><font color="#808080">http://www.blueidea.com/tech/web/2004/2379.asp</font></a><br /></div>
<img src ="http://www.blogjava.net/280211429/aggbug/58687.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/280211429/" target="_blank">国强</a> 2006-07-18 09:50 <a href="http://www.blogjava.net/280211429/articles/58687.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>