对于想了解webjavascript开发之Response.Write与document.writ...的读者,本文将提供新的信息,我们将详细介绍response.write和document.wri
对于想了解web javascript开发 之Response.Write 与document.writ...的读者,本文将提供新的信息,我们将详细介绍response.write和document.write,并且为您提供关于document.open() 与 document.write()的区别_javascript技巧、document.write()内的script、document.write()及其输出内容的样式、位置控制_javascript技巧、document.write的几点使用心得_javascript技巧的有价值信息。
本文目录一览:- web javascript开发 之Response.Write 与document.writ...(response.write和document.write)
- document.open() 与 document.write()的区别_javascript技巧
- document.write()内的script
- document.write()及其输出内容的样式、位置控制_javascript技巧
- document.write的几点使用心得_javascript技巧
web javascript开发 之Response.Write 与document.writ...(response.write和document.write)
Response是ASP的一种对象,用来访问服务器端所创建的并发回到客户端的响应信息。而write是response的一种方法,功能是在当前的HTTP响应信息流和IIS缓冲区写入指定的字符,使之成为返回页面的一部分。说的通俗点,就是从服务器端向客户端浏览器(IE)发送指定的字符。而dosument是javascript的对象,write是他的一种方法,功能也是想浏览器输出文本。
所以说两者作用相似,但是完全不同,一般response.write在服务器端执行,然后向客户端浏览器发送,而document.write在客户端执行,然后向浏览器发送。
分两种情况
1、页面内容是直接由本脚本完成的,此时可用:
response.write images(i)
2、本脚本的页面内容是提供给另一个网页(这个网页是通过调用本脚本)时,用:
response.write "document.write(''" & images(i) & "'');"
response.write images(i)
你这段代码肯定是写在一个javascript函数里面的,所以要用
response.write "document.write(''" & images(i) & "'');"
就是说在服务器端向客户端发送脚本,脚本的内容是document.write(''images(i)的值'');,然后在客户端执行这个脚本,向浏览器输出文本,就是images(i)的值
本质区别是:Response.Write 是服务器端脚本,用的时候需要在开头和结尾用<%%>,而document.write是客户端脚本,用的时候,开关和结尾一般用script.
document.open() 与 document.write()的区别_javascript技巧
document.open() 打开一个新的空白文档,在IE下,open有两个默认参数,相当于document.open("text/html",''""),第二个参数只有一个值可选:replace,如果启用了该值,则新建的文档会覆盖当前页面的文档(相当于清空了原文档里的所有元素,且不能后退即,浏览器的后退按钮不可用);
看一个例子:
<script> <BR><!-- <BR>function test(){ <BR> document.open("text/html","replace"); <BR> document.writeln(Math.random()); <BR> document.write("<input type=''button'' value=''back(第二个按钮)'' onclick=''history.back()''>") <BR> document.close(); <BR> document.open("text/html",""); <BR> document.writeln(Math.random()); <BR> document.write("<input type=''button'' value=''back(第三个按钮)'' onclick=''history.back()''>") <BR> document.close(); <BR> document.open("text/html",""); <BR> document.writeln(Math.random()); <BR> document.write("<input type=''button'' value=''back(第四个按钮)'' onclick=''history.back()''>") <BR> document.close(); <BR>} <BR>//--> <BR></script>
平常都不写document.open() 与 document.close(),因为浏览器会在write之前先open一个文档,再把write的内容输出到原文档里面。write结束后,默认是不会有close的,否则第二行document.write的时候就会覆盖之前的write。
document.write()内的script
我用document.write()动态添加的script内的对象,如何和其他script内的对象交互?
动态添加的可以读取到其他script的,但反过来不行。
document.write()及其输出内容的样式、位置控制_javascript技巧
JS中的最基本的命令之一:document.write(),用于简单的打印内容到页面上,可以逐字打印你需要的内容——document.write("content"),这里content就是需要输出的内容;当然还有一种情况,需要输出JS之中比如变量等等变化的东西,那么就需要用document.write(+variable);当然variable就是你想要输出的变量。
既然可以输出变量,肯定会想要去控制下变量的显示,比如位置以及样式。第一种控制方法是应用内部添加样式的方法,比如
document.write("=font-size:20px;font-family= Helvetica;"content""这样,不过如果里面需要添加的样式太多,那么不仅显得臃肿,而且修改起来也不会方便。
这种情况下肯定用选择器肯定会感觉爽一些。不过由于用选择器的时候要用到各种双引号单引号,所以在使用的时候应该注意防止双引号和单引号的提早匹配,我避免的方法是用 \" 去提醒浏览器不要过早的匹配,例子如下:
document.write("
这里定义了一个名叫ok的ID选择器去控制样式,因id名需要用双引号括起来,所以为了避免和前面的双引号匹配,就用 \" 给它声明一下,然后在CSS文件里面
#ok{style;}
就可以去定义自己想要的样式和位置了。
document.write的几点使用心得_javascript技巧
一直用document.write()方法向浏览器中显示数据用,把它当做Alert()使用, 看来这样用有些大材小用了,下面说说它的主要用处。
document.write()方法可以用在两个方面:
1.页面载入过程中,用脚本加入新的页面内容。
2.用延时脚本创建本窗口或新窗口的内容。
该方法需要一个字符串参数,它是写到窗口或框架中的HTML内容。这些字符串参数可以是变量或值为字符串的表达式,写入的内容常常包括HTML标记语言。如下面代码,教务系统框架载入子页
//加载效果图标

//输出框架
Index.OutputIframe = function () {
var scrolling = $.isIE6 == true ? ''yes'' : ''auto'';
document.write('''');
};