收音机按钮没有显示出来

时间:2014-08-05 16:01:46

标签: javascript html

我必须编辑现有的HTML(更改标题和变量)并通过Firebug运行它。我的单选按钮是盒子(或根本没有显示),我不知道为什么。我附上了HTML代码和Firebug输出的截图。我使用在线转换器将HTML转换为JavaScript。我是JavaScript的新手,很难掌握这个问题。任何帮助将不胜感激!

HTML代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Radio Buttons</TITLE>
<META content=3D"text/html; charset=3Dwindows-1252" =
http-equiv=3DContent-Type>
<SCRIPT type=3Dtext/javascript>
    function pick_a_business_card(){
        var base_cost =3D get_business_card_value();
        alert(base_cost);
    }
    function get_business_card_value(){
        var radio_buttons =3D document.getElementsByName('business card');

        for (var i =3D 0, length =3D radio_buttons.length; i < length; i++) {
        =09
            if (radio_buttons[i].checked) {
                return radio_buttons[i].value;
            }
        }
    }
</SCRIPT>

<META name=3DGENERATOR content=3D"MSHTML 8.00.7601.18129"></HEAD>
<BODY>
    <FORM id=3Dbusiness_card_addons_calculation_form method=3Dpost action=3D#>
    <H2>Radio Buttons</H2>
    <P><STRONG>Pick a Business Card:</STRONG><BR><BR><INPUT id=3Dvertical value=3Dvertical
=
type=3Dradio=20
name=3Dcolor> <LABEL for=3Dvertical>Vertical</LABEL> <BR><INPUT id=3Dhorizontal =
value=3Dhorizontal=20
type=3Dradio name=3Dcolor> <LABEL for=3Dhorizontal>Horizontal</LABEL> <BR><INPUT =
id=3DFoldover=20
value=3Dfoldover type=3Dradio name=3Dcolor> <LABEL for=3DFoldover>Foldover</LABEL> =
</P>
    <P><INPUT onclick=3Dpick_a_business_card() value=3D" Submit " =
type=3Dbutton></P>
</FORM>
</BODY>
</HTML>

1 个答案:

答案 0 :(得分:0)

在您的转化过程中,某些内容似乎编码不当。

我将您的代码清理了一点here,这有助于您入门

以下是完整的HTML:

<html>
<head>
  <script>
    function pick_a_business_card(){ 
      var base_cost = get_business_card_value(); 
      alert(base_cost);

    }
    function get_business_card_value(){
      var radio_buttons = document.getElementsByName('color');

      for (var i = 0, length = radio_buttons.length; i < length; i++) {
        if (radio_buttons[i].checked) {
          return radio_buttons[i].value;
        }
      }
    }
  </script>
</head>
<body>
<FORM id=business_card_addons_calculation_form method=post action=#>
<H2>Radio Buttons</H2>
<P><STRONG>Pick a Business Card:</STRONG><BR><BR><INPUT id=vertical value=vertical
type=radio
name=color> <LABEL for=vertical>Vertical</LABEL> <BR><INPUT id=horizontal
value=horizontal
type=radio name=color> <LABEL for=horizontal>Horizontal</LABEL> <BR><INPUT 
id=Foldover
value=foldover type=radio name=color> <LABEL for=Foldover>Foldover</LABEL>
</P>
<P><INPUT onclick=pick_a_business_card() value=" Submit "
type=button></P></FORM>
</body>
</html>

此外,我建议在HTML属性周围添加引号。

相关问题