如何使用数字作为名称访问表单元素 [英] how to access form elements with numbers as names

查看:54
本文介绍了如何使用数字作为名称访问表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我继承了一些代码,其中包含一些表单元素(单选按钮)

,称为1,2 ;等等


例如:


< input name =" 2"类型= QUOT;无线电" value =" 45">

< input name =" 2"类型= QUOT;无线电" value =" 46">

我希望能够通过javascript访问它们来禁用它们;


forms.myform.2 [0] .disabled = true;




但是当我尝试这样做时出现javascript错误(关于

缺少分号)。

我的javascript技能很好,我有其他元素被禁用OK,

所以我认为这是元素的方式有问题

命名。


不幸的是我没有重命名元素的选项。有没有

另一种访问这些元素的方法?

我试过了:


var temp = forms.myform.2;

temp [0] .disabled = true;


但是我在var temp = ...上得到了相同的分号错误。 line


任何想法都赞赏!


干杯,


Ben

Hi,

I have inherited some code that has some form elements (radio buttons)
that are called "1", "2" etc.

for example:

<input name="2" type="radio" value="45">
<input name="2" type="radio" value="46">
I want to be able to access them through javascript to disable them;

forms.myform.2[0].disabled=true;

etc.
however I get a javascript error when I try to do this (something about a
missing semicolon).
My javascript skills are fine and I have other elements being disabled OK,
so I assume that this is a problem with the way that the elements were
named.

Unfortunately I don''t have the option of renaming the elements. Is there
another way to access these elements?
I have tried:

var temp=forms.myform.2;
temp[0].disabled=true;

But I get the same missing semicolon error on the "var temp=..." line

Any thoughts appreciated!

Cheers,

Ben

推荐答案

Jon Hoowes写道:
Jon Hoowes wrote:


我继承了一些有某种形式的代码元素(单选按钮)
被称为1,2和2。等等

例如:

< input name =" 2"类型= QUOT;无线电" value =" 45">
< input name =" 2"类型= QUOT;无线电" value =" 46">

我希望能够通过javascript访问它们来禁用它们;

forms.myform.2 [0] .disabled = true ;

然而,当我尝试这样做时,我得到一个javascript错误(关于
缺少分号的东西)。
我的javascript技能很好,我有其他元素被禁用OK,
所以我认为这是元素被命名的方式的问题。

不幸的是我没有选择重命名元素。是否有其他方式来访问这些元素?
我试过:

var temp = forms.myform.2;
temp [0] .disabled = true ;

但是我在var temp = ...上得到了相同的缺失分号错误。线路

任何想法都赞赏!

欢呼,

Hi,

I have inherited some code that has some form elements (radio buttons)
that are called "1", "2" etc.

for example:

<input name="2" type="radio" value="45">
<input name="2" type="radio" value="46">
I want to be able to access them through javascript to disable them;

forms.myform.2[0].disabled=true;

etc.
however I get a javascript error when I try to do this (something about a
missing semicolon).
My javascript skills are fine and I have other elements being disabled OK,
so I assume that this is a problem with the way that the elements were
named.

Unfortunately I don''t have the option of renaming the elements. Is there
another way to access these elements?
I have tried:

var temp=forms.myform.2;
temp[0].disabled=true;

But I get the same missing semicolon error on the "var temp=..." line

Any thoughts appreciated!

Cheers,

Ben




嗨Ben ,


也许stringnotation有帮助吗? (不确定)


var temp = forms.myform [" 2"];

temp [0] .disabled = true;


如果没有,请尝试使用alert进行调试。

赞:

var temp = forms.myform [" 2"];

alert(tmp);

temp [0] .disabled = true;


是指向无线电对象的tmp吗? br />

是的:奇怪的设计可以为你的元素命名。 : - /


问候,

Erwin Moller



Hi Ben,

Maybe stringnotation helps? (not sure)

var temp=forms.myform["2"];
temp[0].disabled=true;

If not, try debugging by using alert.
Like:
var temp=forms.myform["2"];
alert (tmp);
temp[0].disabled=true;

is tmp pointing to a radio-object?

And yes: Strange design to name your elements like that. :-/

Regards,
Erwin Moller


嗨Ben,

也许stringnotation有帮助吗? (不确定)

var temp = forms.myform [" 2"];
temp [0] .disabled = true;

如果没有,请尝试使用alert进行调试。
喜欢:
var temp = forms.myform [" 2"];
alert(tmp);
temp [0] .disabled = true;

指向一个无线电对象?

是的:奇怪的设计可以为你的元素命名。 : - /

问候,
Erwin Moller
Hi Ben,

Maybe stringnotation helps? (not sure)

var temp=forms.myform["2"];
temp[0].disabled=true;

If not, try debugging by using alert.
Like:
var temp=forms.myform["2"];
alert (tmp);
temp[0].disabled=true;

is tmp pointing to a radio-object?

And yes: Strange design to name your elements like that. :-/

Regards,
Erwin Moller




还有一件事,我在使用元素之前总是使用文档。 />
所以:

var temp = document.forms.myform [" 2"];


问候,

Erwin Moller



One more thing, I always use document too before adressing elements.
So:
var temp=document.forms.myform["2"];

Regards,
Erwin Moller


也许字符串有用吗? (不确定)

var temp = forms.myform [" 2"];
temp [0] .disabled = true;


这样可行,但不允许我通过他们的名称来访问元素

和是:奇怪的设计将你的元素命名为那。 : - /
Maybe stringnotation helps? (not sure)

var temp=forms.myform["2"];
temp[0].disabled=true;
This works, but doesn''t allow me to access the elements by their "name"
And yes: Strange design to name your elements like that. :-/




这是一个基于数据库信息构建表单的系统。

主键是一个数字,它决定了元素的名称。


这也是你提出的建议不合适的原因 - 它有效,但是我

不能保证表格中每个元素的顺序:(


干杯无论如何!


乔恩



It''s a system that builds a form based on database information. The
primary key, which is a number, determines the name of the element.

This is also why the suggestion you made is not suitable - it works, but I
cannot guarantee the order of each element within the form :(

Cheers anyway!

Jon


这篇关于如何使用数字作为名称访问表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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