Javascript Bug? [英] Javascript Bug?

查看:62
本文介绍了Javascript Bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在表格上选择哪个单选按钮并且

我正在使用:


//alert(document.CC.Ecom_Payment_Card_Type。 (b)(var i = 0; i< document.CC.Ecom_Payment_Card_Type.length; i + +){

if(document.CC.Ecom_Payment_Card_Type [i]。)
for。已检查){

var CardType =

document.CC.Ecom_Payment_Card_Type [i] .value

}

}

如果有2个或更多单选按钮,这样可以正常工作,但是如果有
只有一个,则会失败。如果我取消注释它的警告说,长度是

未定义,当它应该是1.任何人都知道问题是什么以及如何我可以绕过它?b $ b br />

Marshall

I am wanting to deteremine which radio button is selected on a form and
am using:

//alert(document.CC.Ecom_Payment_Card_Type.length)
for (var i=0;i<document.CC.Ecom_Payment_Card_Type.length;i+ +) {
if (document.CC.Ecom_Payment_Card_Type[i].checked) {
var CardType =
document.CC.Ecom_Payment_Card_Type[i].value
}
}
This works fine if there are 2 or more radio buttons, but if there is
only one, it fails. The alert if I uncomment it says that the length is
undefined, when it should be 1. Anyone know what the problem is and how
I can get around it?

Marshall

推荐答案

Marshall Dudley说:
Marshall Dudley said:

我想要在表格上选择哪个单选按钮并且正在使用:

//alert(document.CC.Ecom_Payment_Card_Type.length)
for( var i = 0; i< document.CC.Ecom_Payment_Card_Type.length; i + +){
if(document.CC.Ecom_Payment_Card_Type [i] .checked){
var CardType =
文件。 CC.Ecom_Payment_Card_Type [i] .value
}
}

如果有2个或更多单选按钮,这个工作正常,但是如果只有一个,那么失败。警告如果我取消注释它说长度是未定义的,当它应该是1.任何人都知道问题是什么以及我可以如何解决它?

I am wanting to deteremine which radio button is selected on a form and
am using:

//alert(document.CC.Ecom_Payment_Card_Type.length)
for (var i=0;i<document.CC.Ecom_Payment_Card_Type.length;i+ +) {
if (document.CC.Ecom_Payment_Card_Type[i].checked) {
var CardType =
document.CC.Ecom_Payment_Card_Type[i].value
}
}
This works fine if there are 2 or more radio buttons, but if there is
only one, it fails. The alert if I uncomment it says that the length is
undefined, when it should be 1. Anyone know what the problem is and how
I can get around it?




它与Javascript无关,它是如何定义DOM的。

如果只有一个具有给定名称的表单控件,它'没有建模

作为一个数组,因此它没有长度属性。


在尝试使用它之前测试是否存在length属性。



It''s got nothing to do with Javascript, it''s how the DOM is defined.
If there is only one form control with a given name, it''s not modeled
as an array, and so it has no length attribute.

Test for the existence of the length attribute before trying to use it.


Marshall Dudley写道:

< snip>
Marshall Dudley wrote:
<snip>
如果有2个,这个工作正常或者更多单选按钮,但如果只有一个单选按钮,则会失败。警报如果我取消注释
它表示长度未定义,应该是1.
任何人都知道问题是什么以及我如何绕过它?
This works fine if there are 2 or more radio buttons, but
if there is only one, it fails. The alert if I uncomment
it says that the length is undefined, when it should be 1.
Anyone know what the problem is and how I can get around it?




< URL: http:// www .jibbering.com / faq / faq_notes / form_access.html >


Richard。



<URL: http://www.jibbering.com/faq/faq_notes/form_access.html >

Richard.


Lee写道:
Marshall Dudley说:
Marshall Dudley said:



[...]


[...]

<如果有2个或更多单选按钮,这样可以正常工作,但如果只有一个单选按钮,则会失败。警告如果我取消注释它说长度是未定义的,当它应该是1.任何人都知道问题是什么以及我如何绕过它?

This works fine if there are 2 or more radio buttons, but if there is
only one, it fails. The alert if I uncomment it says that the length is
undefined, when it should be 1. Anyone know what the problem is and how
I can get around it?



它与Javascript无关,它是如何定义DOM的。
如果只有一个具有给定名称的表单控件,则它没有建模
作为数组,因此它没有长度属性。


It''s got nothing to do with Javascript, it''s how the DOM is defined.
If there is only one form control with a given name, it''s not modeled
as an array, and so it has no length attribute.




此外,单选按钮不应单独使用。如果指示了一个

可检查元素,则它应该是一个复选框。尝试取消选中

a单独的单选按钮。


应始终选择一个单选按钮(但浏览器不执行

它)。一旦选择了一个按钮,就没有其他人可以检查了。

如果不重新设置表单,你就不能取消选中它。一些

浏览器开发人员也可能决定检查第一个单选按钮

默认如果页面作者还没决定哪一个应该由
$检查b $ b默认(我不知道有没有这样做,但规格可能是

这样解释)。


< URL :http://www.w3.org/TR/html4/interact/forms.html#radio>


[...]


-

Rob



Further, radio buttons should never be used singly. If a single
checkable element is indicated, it should be a checkbox. Try to uncheck
a solitary radio button.

One radio button should always be selected (but browsers don''t enforce
it). Once a single button is selected, there are no others to check so
you can''t uncheck a solo button it without re-setting the form. Some
browser developer may also decide to check the first radio button by
default if the page author hasn''t decided which one should be checked by
default (I don''t know of any that do so, but the specification could be
interpreted that way).

<URL:http://www.w3.org/TR/html4/interact/forms.html#radio>

[...]

--
Rob


这篇关于Javascript Bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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