使用子句语法错误,但我该如何解决? [英] With clause syntax errors but how do I fix it?

查看:58
本文介绍了使用子句语法错误,但我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< script>

<! -


函数isValidAlert(){

for(var i = 0; i< document.alertForm.length; i ++){

with(document.alertForm.elements [i]){

if(.name ==" text" || .name ==" password" || .name ==" textarea"){

if(.value ==""){

alert(请输入&。+ .name);

focus();

返回false;

}

}否则if(.name ==" select-one"){

if(.options [document.alertForm.elements [i] .selectedIndex] .value ==

""){

alert(" Please select a" + .name);

return false;

}

}

}

}

}


// - >

< / script>


我不知道这个问题的答案,我得到了语法错误,并且

" with"在任何Javascript教程上搜索都不好。所以这是我唯一获得帮助的

选项;谁能告诉我我做错了什么?


Thanx

Phil

解决方案

< blockquote>

< script>
<! -

function isValidAlert(){
for(var i = 0; i< document.alertForm.length; i ++){
with(document.alertForm.elements [i]){
if(.name ==" text" || .name ==" password" || .name ==" textarea"){
if(.value ==""){
alert(" Please enter a" + .name);
focus();
return false;
}
} if if(.name ==" ; select-one){
if(.options [document.alertForm.elements [i] .selectedIndex] .value ==
""){
alert(" Please)选择+ .name;
返回false;
}
}
}
}
}

/ / - > <无线电通信/>< / script>

我不知道这个问题的答案,我得到语法错误,并且
with在任何Javascript教程上搜索都不好。所以这是我唯一的帮助选项;谁能告诉我我做错了什么?

Thanx
Phil




" with"在VB工作,但据我所知,它不是在JavaScript中。它还没有大多数现有语言的b $ b。无论如何,它使代码

不可读,总而言之,最好不要使用它。


如果你想简化长或复杂的结构,你可以随时

重新声明它们:


var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;


myText.value =" Hello world";


Laurent

-

Laurent Bugnion,GalaSoft

网页设计,Java,javascript http:// www .galasoft-LB.ch

私人/马来西亚: http://mypage.bluewin.ch/lbugnion

支持加尔各答的儿童: http://www.calcutta-espoir.ch


更正,我错了。见下文。


Laurent Bugnion,GalaSoft写道:



Phil Powell写道:

< script>
<! -

函数isValidAlert(){
for(var i = 0; i< document .alertForm.length; i ++){
with(document.alertForm.elements [i]){
if(.name ==" text" || .name ==" password" || .name ==" textarea"){
if(.value ==""){
alert(" Please enter a" + .name);
focus( );
返回false;
}
} if if(.name ==" select-one"){
if(.options [document.alertForm.elements [i ] .selectedIndex] .value ==
""){
alert(" Please select a" + .name);
return false;
}
}
}
}

// - >
< / script>

我不要知道这个问题的答案的问题,我得到的语法错误,并
"与"在任何Javascript教程上搜索都不好。所以这是我的唯一帮助选项;谁能告诉我我做错了什么?

Thanx
Phil



" with在VB工作,但据我所知,它不是在JavaScript中。它还没有大多数现有的语言。无论如何,它使代码不可读,总而言之,最好不要使用它。

如果你想简化长或复杂的结构,你总是可以
重新宣布:

var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;

myText.value =" Hello world";

Laurent




好​​的,我错了。存在于JavaScript中,如本示例所述:


当代码段为
使用多个数学常量时,使用with语句通常很方便方法,所以你不必输入

" Math"反复。例如,


with(Math){

a = PI * r * r

y = r * sin(theta)

x = r * cos(theta)

}


因此语法不同(你不能使用'' 就像在VB中一样。


但是,我认为使用它是不好的做法,而且我确实是b $ b建议你不要。


HTH,


Laurent

-

Laurent Bugnion,GalaSoft

网页设计,Java,javascript http://www.galasoft-LB.ch

私人/马来西亚: http://mypage.bluewin.ch/lbugnion

支持加尔各答的孩子: http://www.calcutta-espoir.ch


哇,这种或那种方式该死......这太糟糕了! />

我不知道什么是不可读的,你如何看待与...子句,或者:


document.alertForm.elements [i] .options [document.alertForm.elements [i] .select

edIndex] .value


我觉得自己完全不可读!我试图提出一个优雅且可读的解决方案来解析客户端

验证的表单元素。 :(


我记得你在VB中使用。。对不起,但它现在是


VB 1
Javascript 0


因为潜在的数据冲突而不使用。这是非常不安全的。


Phil


" Laurent Bugnion,GalaSoft" galasoft-LB@bluewin_NO_SPAM.ch>写在

消息新闻:3f ******* *@news.bluewin.ch ...

更正,我错了。见下文。

Laurent Bugnion,GalaSoft写道:



Phil Powell写道:

< script>
<! -

function isValidAlert(){
for(var i = 0; i< document.alertForm.length; i ++){
with(document.alertForm.elements [i]){
if( .name ==" text" || .name ==" password" || .name ==" textarea")
{if(.value ==""){
警报(QUOT;请输入 + .name);
focus();
返回false;
}
} if if(.name ==" select-one"){
if (.options [document.alertForm.elements [i] .selectedIndex] .value
==""){
alert(" Please select a" + .name);
返回错误;
}
}
}
}

// - >
< /脚本>

我不知道这个问题的答案,我收到语法错误,
和with;在任何Javascript教程上搜索都不好。所以这是我的唯一帮助选项;谁能告诉我我做错了什么?

Thanx
Phil



" with在VB工作,但据我所知,它不是在JavaScript中。它还没有大多数现有的语言。无论如何,它使代码不可读,总而言之,最好不要使用它。

如果你想简化长或复杂的结构,你总是可以
重新宣布:

var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;

myText.value =" Hello world";

Laurent



好的,我错了。存在于JavaScript中,如本例所述:

当一段代码使用几个数学常量和方法时,使用with语句通常很方便,所以你不要必须输入
数学反复。例如,

与(数学){
a = PI * r * r
y = r * sin(theta)
x = r * cos(theta) )
}

所以语法不同(你不会像VB那样使用''''。)

然而,我站着,因为使用它是不好的做法,而且我确实建议你不要。

HTH,

Laurent
-
Laurent Bugnion,GalaSoft
网页设计,Java,javascript http://www.galasoft-LB.ch
私人/马来西亚: http://mypage.bluewin.ch/lbugnion
支持加尔各答的儿童: http://www.calcutta-espoir.ch



<script>
<!--

function isValidAlert() {
for (var i = 0; i < document.alertForm.length; i++) {
with (document.alertForm.elements[i]) {
if (.name == "text" || .name == "password" || .name == "textarea") {
if (.value == "") {
alert("Please enter a " + .name);
focus();
return false;
}
} else if (.name == "select-one") {
if (.options[document.alertForm.elements[i].selectedIndex].value ==
"") {
alert("Please select a " + .name);
return false;
}
}
}
}
}

//-->
</script>

I don''t know the answer to this problem, I am getting syntax errors, and
"with" does not search well on any Javascript tutorial. So this is my only
option for help; can someone tell me what I did wrong?

Thanx
Phil

解决方案

Hi,

Phil Powell wrote:

<script>
<!--

function isValidAlert() {
for (var i = 0; i < document.alertForm.length; i++) {
with (document.alertForm.elements[i]) {
if (.name == "text" || .name == "password" || .name == "textarea") {
if (.value == "") {
alert("Please enter a " + .name);
focus();
return false;
}
} else if (.name == "select-one") {
if (.options[document.alertForm.elements[i].selectedIndex].value ==
"") {
alert("Please select a " + .name);
return false;
}
}
}
}
}

//-->
</script>

I don''t know the answer to this problem, I am getting syntax errors, and
"with" does not search well on any Javascript tutorial. So this is my only
option for help; can someone tell me what I did wrong?

Thanx
Phil



"with" works in VB, but as far as I know, it doesn''t in JavaScript. It
also doesn''t in most current languages. Anyway, it makes the code
unreadable, and all in all it is good practice to not use it.

If you want to simplify long or complicated structures, you can always
redeclare them:

var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;

myText.value = "Hello world";

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch


Correction, I was wrong. See below.

Laurent Bugnion, GalaSoft wrote:

Hi,

Phil Powell wrote:

<script>
<!--

function isValidAlert() {
for (var i = 0; i < document.alertForm.length; i++) {
with (document.alertForm.elements[i]) {
if (.name == "text" || .name == "password" || .name == "textarea") {
if (.value == "") {
alert("Please enter a " + .name);
focus();
return false;
}
} else if (.name == "select-one") {
if (.options[document.alertForm.elements[i].selectedIndex].value ==
"") {
alert("Please select a " + .name);
return false;
}
}
}
}
}

//-->
</script>

I don''t know the answer to this problem, I am getting syntax errors, and
"with" does not search well on any Javascript tutorial. So this is my
only
option for help; can someone tell me what I did wrong?

Thanx
Phil


"with" works in VB, but as far as I know, it doesn''t in JavaScript. It
also doesn''t in most current languages. Anyway, it makes the code
unreadable, and all in all it is good practice to not use it.

If you want to simplify long or complicated structures, you can always
redeclare them:

var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;

myText.value = "Hello world";

Laurent



OK, I was wrong. With exists in JavaScript, as described in this example:

It is often convenient to use the with statement when a section of code
uses several math constants and methods, so you don''t have to type
"Math" repeatedly. For example,

with (Math) {
a = PI * r*r
y = r*sin(theta)
x = r*cos(theta)
}

So the syntax is different (you don''t use the ''.'' like in VB).

I stand, however, by the fact that it''s bad practice to use it, and I
really recommend that you don''t.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch


Wow, damned one way or another.. that is awful!

I don''t know what is more unreadable, how you view a "with" clause, or this:

document.alertForm.elements[i].options[document.alertForm.elements[i].select
edIndex].value

I think that is utterly unreadable myself! I was trying to come up with an
elegant and readable solution to parse through form elements for client-side
validation. :(

I remember you use "." in VB. Sorry but it''s now

VB 1
Javascript 0

That is very unsafe to not use "." because of potential data collision.

Phil

"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3f********@news.bluewin.ch...

Correction, I was wrong. See below.

Laurent Bugnion, GalaSoft wrote:

Hi,

Phil Powell wrote:

<script>
<!--

function isValidAlert() {
for (var i = 0; i < document.alertForm.length; i++) {
with (document.alertForm.elements[i]) {
if (.name == "text" || .name == "password" || .name == "textarea") { if (.value == "") {
alert("Please enter a " + .name);
focus();
return false;
}
} else if (.name == "select-one") {
if (.options[document.alertForm.elements[i].selectedIndex].value == "") {
alert("Please select a " + .name);
return false;
}
}
}
}
}

//-->
</script>

I don''t know the answer to this problem, I am getting syntax errors, and "with" does not search well on any Javascript tutorial. So this is my
only
option for help; can someone tell me what I did wrong?

Thanx
Phil


"with" works in VB, but as far as I know, it doesn''t in JavaScript. It
also doesn''t in most current languages. Anyway, it makes the code
unreadable, and all in all it is good practice to not use it.

If you want to simplify long or complicated structures, you can always
redeclare them:

var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;

myText.value = "Hello world";

Laurent



OK, I was wrong. With exists in JavaScript, as described in this example:

It is often convenient to use the with statement when a section of code
uses several math constants and methods, so you don''t have to type
"Math" repeatedly. For example,

with (Math) {
a = PI * r*r
y = r*sin(theta)
x = r*cos(theta)
}

So the syntax is different (you don''t use the ''.'' like in VB).

I stand, however, by the fact that it''s bad practice to use it, and I
really recommend that you don''t.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch



这篇关于使用子句语法错误,但我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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