是否所有javascript(如location.href)都要求声明javascript? [英] Does all javascript (like location.href) require that javascript be declared?

查看:85
本文介绍了是否所有javascript(如location.href)都要求声明javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在学习javascript并对

location.href有疑问。 javascript是否始终要求< script language =

" javascript">

(或脚本类型=" text / javascript">)才能运行?


我在问,因为下面的代码块(

下拉菜单进入页面的不同部分)无需声明任何地方

它是javascript


< form>

< select name ="图书馆

onchange =" location.href = this.form.Library [this.form.Library.selectedIndex] .value">

< option value = "#First"> First< / option>

< option value ="#Second"> Second< / option>

< option value = "#Third"> Third< / option>

< / select>

< / form>

< a name = QUOT;首先">首先章节< / A><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>

< a nam E ="第二">第二个章节< / A><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>

将一个名称= QUOT;第三">第三章节< / A><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>< ; br>


" location.href"是javascript,对吧? (我在他们的下拉菜单中了解了
www.dartmouth.edu 页面菜单)。


我感谢任何关于此的帮助/解释!!


Andrea

Hi everyone,

I am in the process of learning javascript and have a question on
location.href. Does javascript always require the <script language =
"javascript">
(or script type="text/javascript">) to run?

I''m asking because the following chunk of code (drop down menu that
goes to different parts of the page) works without declaring anywhere
that it''s javascript:

<form>
<select name="Library"
onchange="location.href=this.form.Library[this.form.Library.selectedIndex].value">
<option value="#First">First</option>
<option value="#Second">Second</option>
<option value="#Third">Third</option>
</select>
</form>
<a name="First">First Section</a><br><br><br><br><br><br><br><br>
<a name="Second">Second Section</a><br><br><br><br><br><br><br><br>
<a name="Third">Third Section</a><br><br><br><br><br><br><br><br>

"location.href" is javascript, right?? (I learned it off the
www.dartmouth.edu page in their drop down menu).

I appreciate any help/explanation on this!!

Andrea

推荐答案

am*****@yahoo.com (Andrea)写道:
am*****@yahoo.com (Andrea) writes:
我正在学习javascript并对
location.href有疑问。 javascript是否始终需要运行< script language =
" javascript">
(或脚本类型=" text / javascript">)?


不,在某些情况下隐含的内容是

Javascript。


它是< script type =" text / javascript"> ;,顺便说一句,语言版本是

已弃用。

我要问因为下面的代码块(下拉菜单,
转到页面的不同部分)工作时没有声明任何地方
它是javascript

< form>
< select name =" Library"
onchange =" location.href = this.form.Library [this.form.Library.selectedIndex] .value">


是的,onchage属性值是* inline * Javascript,就像

< div style =" border:1px solid red;"> ;

将内联CSS作为样式属性的值。

我感谢任何帮助/解释!!
I am in the process of learning javascript and have a question on
location.href. Does javascript always require the <script language =
"javascript">
(or script type="text/javascript">) to run?
No, there are some cases where it is implicit that the content is
Javascript.

It is <script type="text/javascript">, btw, the language version is
deprecated.
I''m asking because the following chunk of code (drop down menu that
goes to different parts of the page) works without declaring anywhere
that it''s javascript:

<form>
<select name="Library"
onchange="location.href=this.form.Library[this.form.Library.selectedIndex].value">
Yes, the onchage attribute value is *inline* Javascript, just like
<div style="border:1px solid red;">
has inline CSS as value of the style attribute.
I appreciate any help/explanation on this!!




内联脚本的默认脚本语言是所有

浏览器中的javascript。如果你想明确声明它,你可以使用

Content-Script-Type元标题,由服务器发送或写成

内联为


< meta http-equiv =" Content-Script-Type" content =" text / javascript">



< meta http-equiv =" Content-Script-Type" content =" text / vbscript">


(类似于Content-Style-Type,如果还有其他选项

比CSS)


有些人错误地写了

onchange =" javascript :..."

这不会将内容声明为javascript,它只会解析

javascript :作为一个Javascript标签。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

Art D''HTML:< URL:http://www.infimum.dk/HTML/randomArtSplit.html>

''没有判断的信仰只会降低精神神圣。''



The default script language for inline scripts is javascript in all
browsers. If you want to declare it explicitly, you can use the
Content-Script-Type meta header, either sent by the server or written
inline as

<meta http-equiv="Content-Script-Type" content="text/javascript">
or
<meta http-equiv="Content-Script-Type" content="text/vbscript">

(and similar for Content-Style-Type, if there was any other option
than CSS)

What some people mistakenly do is to write
onchange="javascript:..."
That does not declare the content as javascript, it merely parses
the "javascript:" as a Javascript lable.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D''HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
''Faith without judgement merely degrades the spirit divine.''


如果没有声明,javascript是默认语言。
然而,
,明确宣布它是没有害处的,比

对不起更安全....

只是fyi,在某些时候你可能想看看如何声明语言

版本例如< script language =" JavaScript1.1">

甚至语言语法,例如< script language =" JScript">

可用于在不同的浏览器中运行不同的代码块。


-alu


" Andrea" <是***** @ yahoo.com>在留言中写道

news:99 ************************** @ posting.google.c om ...
javascript is the default language if none is declared.
however, is no harm in declaring it explicitly, and better safe than
sorry....
just fyi, at some time you may like to look into how declaring the language
version e.g. <script language="JavaScript1.1">
or even language syntax e.g. <script language="JScript">
can be used to run different blocks of code in different browsers.

-alu

"Andrea" <am*****@yahoo.com> wrote in message
news:99**************************@posting.google.c om...
大家好,

我正在学习javascript并对
location.href有疑问。 javascript是否始终需要< script language =
" javascript">
(或脚本类型=" text / javascript">)来运行?

我我问,因为下面的代码块(下拉菜单,
进入页面的不同部分)可以正常工作,而不会在任何地方声明它是javascript

< form>
< select name =" Library"

onchange =" location.href = this.form.Library [this.form。 Library.selectedIndex] .v

alue"> < option value =" #First"> First< / option>
< option value ="#Second"> Second< / option>
< option value ="#第三个>第三个< /选项>
< / select>
< / form>
< a name =" First"> First Section< / a>< BR><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>
<一个名称= QUOT;第二">第二个章节< / A> ;<峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>
<一个名称= QUOT;第三">第三章节< ; / A><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br><峰; br>

" location.href"是javascript,对吧? (我在他们的下拉菜单中了解了
www.dartmouth.edu 页面菜单)。

我感谢任何帮助/解释!!

Andrea
Hi everyone,

I am in the process of learning javascript and have a question on
location.href. Does javascript always require the <script language =
"javascript">
(or script type="text/javascript">) to run?

I''m asking because the following chunk of code (drop down menu that
goes to different parts of the page) works without declaring anywhere
that it''s javascript:

<form>
<select name="Library"
onchange="location.href=this.form.Library[this.form.Library.selectedIndex].v
alue"> <option value="#First">First</option>
<option value="#Second">Second</option>
<option value="#Third">Third</option>
</select>
</form>
<a name="First">First Section</a><br><br><br><br><br><br><br><br>
<a name="Second">Second Section</a><br><br><br><br><br><br><br><br>
<a name="Third">Third Section</a><br><br><br><br><br><br><br><br>

"location.href" is javascript, right?? (I learned it off the
www.dartmouth.edu page in their drop down menu).

I appreciate any help/explanation on this!!

Andrea



On 2003年7月4日17:56:37 +0200,Lasse Reichstein Nielsen

< lr*@hotpop.com>写道:
On 04 Jul 2003 17:56:37 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
am ***** @ yahoo.com(Andrea)写道:

不,有些情况下隐含的内容是Javascript。


我认为没有任何标准,只有实际的标准

到目前为止在浏览器中实现了什么。 br />

例如 http://www.w3.org/TR/html401/ interact / scripts.html 表示

"未指定默认脚本语言信息的文档

并且包含指定内部事件脚本的元素是

不正确。


(当然,元黑客是如此严格指定,反正一个坏主意

我抵制它...)

有些人误做的是写
onchange =" javascript :..."
那不宣布内容为javascript,它只是解析了javascript :作为一个Javascript标签。
am*****@yahoo.com (Andrea) write:

No, there are some cases where it is implicit that the content is
Javascript.
I don''t think there are in any standard, only in de-facto standards of
what''s implemented in browsers so far.

e.g. http://www.w3.org/TR/html401/interact/scripts.html says
"Documents that do not specify default scripting language information
and that contain elements that specify an intrinsic event script are
incorrect."

(of course the meta hack is so badly specified, and a bad idea anyway
that I boycott it...)
What some people mistakenly do is to write
onchange="javascript:..."
That does not declare the content as javascript, it merely parses
the "javascript:" as a Javascript lable.




除了在IE中它声明为javascript ...它也是

在IE中相对微不足道配置一个不同的默认脚本

语言到javascript,我有一个IE,其中perlscript是默认的

例如。


吉姆。

-

comp.lang.javascript常见问题 - http://jibbering.com/faq/



Except in IE where it does declare as javascript... It''s also
relatively trivial in IE to configure a different default scripting
language to javascript, I have an IE where perlscript is the default
for example.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/


这篇关于是否所有javascript(如location.href)都要求声明javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆