首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

HTML中的alert的运用,帮帮忙,该怎么处理

2012-03-02 
HTML中的alert的运用,帮帮忙%@pagelanguage java pageEncoding ISO-8859-1 %%@tagliburi http:

HTML中的alert的运用,帮帮忙
<%@   page   language= "java "   pageEncoding= "ISO-8859-1 "%>
<%@   taglib   uri= "http://struts.apache.org/tags-bean "   prefix= "bean "   %>
<%@   taglib   uri= "http://struts.apache.org/tags-html "   prefix= "html "   %>
<%@   taglib   uri= "http://struts.apache.org/tags-logic "   prefix= "logic "   %>
<%@   taglib   uri= "http://struts.apache.org/tags-tiles "   prefix= "tiles "   %>
<html>
    <head>
        <title> MyJsp.jsp </title>
        <script   type= "text/javascript ">
function   al()
{
alert(radio1.value);
}
        </script>
</head>
<body>
<table   width= "100% "   border= "1 "   height= "40% ">
<tr> <td   align=center   width= "40% "   height=400>
<table>
  <tr> <td> <strong> 请输入编号 </strong> <br> <input   type=text   name=number   /> </td> </tr>
              </table>
    </td>
<td> <strong> 点击选择类型 </strong>
  <br> <input   type= "radio "   name= "radio1 "   checked=checked   value= "A "   /> A
  <br> <input   type= "radio "   name= "radio1 "   value= "B "   /> B
  <br> <input   type= "radio "   name= "radio1 "   value= "C "   /> C
  <br>
  <br> <input   type=button   name=cancle   value= "取消 "/>
    <input   type=button   name=next   value= "上一步 "   />
            <input   type=button   name=next   value= "进入 ";   onclick= "al() "   />
</td> </tr>
</table>
  </body>
</html>


我按了进入按钮后,就提示undefine,请问一下哪里错了?


[解决办法]
<script>
function b()
{
o = document.getElementsByName( "a ");
for(c=0;c <o.length;c++)
{
if(o[c].checked) alert(o[c].value);
}
}
</script>
<input type= "radio " name= "a " value= "a ">
<input type= "radio " name= "a " value= "b ">
<input type= "radio " name= "a " value= "c ">
<input type= "button " onclick= "b() ">
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script type= "text/javascript ">
function al()
{
var radio1 = document.getElementsByTagName( "input ");


for(var i=0;i <radio1.length;i++)
{
if(radio1[i].getAttribute( "checked ")){
alert(radio1[i].getAttribute( "value "));
}
}
}
</script>
</head>

<body>
<table width= "100% " border= "1 " height= "40% ">
<tr> <td align=center width= "40% " height=400>
<table>
  <tr> <td> <strong> 请输入编号 </strong> <br> <input type=text name=number /> </td> </tr>
  </table>
</td>
<td> <strong> 点击选择类型 </strong>
  <br> <input type= "radio " name= "radio1 " checked= "checked " value= "A " /> A
  <br> <input type= "radio " name= "radio1 " value= "B " /> B
  <br> <input type= "radio " name= "radio1 " value= "C " /> C
  <br>
  <br> <input type=button name=cancle value= "取消 " />
    <input type=button name=next value= "上一步 " />
<input type=button name=next value= "进入 "; onclick= "al() " />
</td> </tr>
</table>
</body>
</html>

[解决办法]
错误的原因:radio1.value中的radio1为数组,要获取选择的radio值,应该这样:
function al()
{
var rd=document.getElementsByName( "radio1 ");//获得所有名为radio1的对象数组
//遍历rd,找到选择的radio
for(i=0;i <rd.length;i++)
{
if(rd[i].getAttribute( "type ")== "radio " && rd[i].checked)
{
alert(rd[i].value);
break;
}
}
}

热点排行