javascript Response.write 与 Document.write
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9815827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Response.write vs Document.write
提问by user798719
Inside a classic asp page, I'm told that you can use vbscript or jscript. And jscript is just javascript.
在经典的 asp 页面中,有人告诉我您可以使用 vbscript 或 jscript。而 jscript 只是 javascript。
So I'm not sure what the difference is between Response.Write, Response.Write(), response.write(), and document.write()
所以我不确定 Response.Write、Response.Write()、response.write() 和 document.write() 之间有什么区别
Does the capitalization matter, and sometimes I seem to see no parentheses after the method name, and sometimes I do. It's all devolving into a mess inside my newbie head.
大小写是否重要,有时我似乎在方法名称后没有看到括号,有时我确实看到了。这一切都在我的新手头脑中变得一团糟。
If I'm writing classic asp using JScript (and not VBScript), should everything inside <% %> be considered javascript, just on the server side?
如果我正在使用 JScript(而不是 VBScript)编写经典的 asp,<% %> 中的所有内容都应该被视为 javascript,只是在服务器端?
Prior to classic asp, I was sure that javascript was a client-side scripting language only.
在经典 asp 出现之前,我确信 javascript 只是一种客户端脚本语言。
采纳答案by RedFilter
You can use VBScriptor JScriptas your language when writing classic ASP server-side code.
在编写经典的 ASP 服务器端代码时,您可以使用VBScript或JScript作为您的语言。
From Wikipedia:
来自维基百科:
JScript is Microsoft's implementation of the ECMAScript standard that is used in Microsoft's Internet Explorer.
JScript 是 Microsoft 在 Microsoft 的 Internet Explorer 中使用的 ECMAScript 标准的实现。
You can also use it in classic ASP, and it has some additional objects available (Response, Request, Application, Session, etc) so that you can do server-side web programming.
你也可以在经典的 ASP 中使用它,它有一些额外的可用对象(响应、请求、应用程序、会话等),以便你可以进行服务器端 Web 编程。
If I was required to write classic ASP, I would definitely choose JScript. Each language has its own syntax requirements that you will need to learn whichever you choose.
如果要我写经典的ASP,我肯定会选择JScript。每种语言都有自己的语法要求,无论您选择哪种语言,您都需要学习这些要求。
document.write()
is not used server-side to send data back to the client, you always use the Response
object for that.
document.write()
不使用服务器端将数据发送回客户端,您始终Response
为此使用该对象。
If I'm writing classic asp using JScript (and not VBScript), should everything inside <% %>be considered javascript, just on the server side?
如果我正在使用 JScript(而不是 VBScript)编写经典的 asp,是否应该将 <% %> 中的所有内容都视为 javascript,只是在服务器端?
Depends on the context—generally the syntax is the same. Stick with Microsoft's JScript documentation and you'll be fine.
取决于上下文——通常语法是相同的。坚持使用 Microsoft 的 JScript 文档,您会没事的。
回答by jeremysawesome
So I'm not sure what the difference is between Response.Write, Response.Write(), response.write(), and document.write()
所以我不确定 Response.Write、Response.Write()、response.write() 和 document.write() 之间有什么区别
If they all work, then I would suggest to just pick one and go with it. Though, I remember reading that you should not use document
on the server side.
如果它们都有效,那么我建议只选择一个并使用它。不过,我记得读过你不应该document
在服务器端使用。
No, you don't have to worry about the capitalization in vbscript. It really comes down to personal preference. I like to use Response.Write()
myself, but I've seen response.write
littered throughout source code as well.
不,您不必担心 vbscript 中的大小写。这真的归结为个人喜好。我喜欢使用Response.Write()
自己,但我也看到过大量的response.write
源代码。
Methods with parentheses vs methods without parentheses.The difference is the type of method. Vbscript supports sub
and function
methods. A sub
is used when no data is meant to be returned and a function
is used when data is to be returned. A sub
method takes it's parameters without parentheses (the server will complain if you try to call a sub
with parentheses and more than one parameter). A function
takes it's parameters with parentheses. Don't ask me why the creators chose to do it this way, it annoys the heck out of me.
带括号的方法与不带括号的方法。区别在于方法的类型。Vbscript 支持sub
和function
方法。sub
当不打算返回任何数据时使用A ,当要返回function
数据时使用a 。一种sub
方法采用不带括号的参数(如果您尝试调用sub
带有括号和多个参数的方法,服务器会抱怨)。Afunction
接受带括号的参数。不要问我为什么创作者选择这样做,这让我很恼火。
JavaScript can be used on the server with classic asp. It actually can come in handy if you are wanting to pass JSON around https://stackoverflow.com/a/1021848/296889.
JavaScript 可以在带有经典 asp 的服务器上使用。如果您想在https://stackoverflow.com/a/1021848/296889周围传递 JSON,它实际上可以派上用场。
回答by bluegman991
Yes capitalization does matter. VB tends to lean towards pascal casing for methods, so .Write()
would be correct in vb. But .write()
would be correct in javascript. If it is a predefined function that is.
是的,大小写很重要。对于方法,VB 倾向于使用 pascal 大小写,因此.Write()
在 vb 中是正确的。但.write()
在javascript中是正确的。如果它是一个预定义的函数。
No everything inside the <% %> tags would not be considered javascript, it would be considered asp.
<% %> 标签内的所有内容都不会被视为 javascript,而是会被视为 asp。