LZOXAnn
2016-11-29 08:13
采纳率: 14.3%
浏览 4.6k
已采纳

button 的onclick事件怎么也不触发。请帮忙。谢谢




<html>
<head>
<script language="JavaScript" type="text/javascript">

function butRemoveWed_onclick()
{
  if (document.form1.theDay.options[2].text == "Wednesday")
   {
      document.form1.theDay.options[2]=null;
    }
 else
   {
      alert("There is no Wednesday here!");
   }
}


function butAddWed_onclick()
{
   if (document.form1.theDay.options[2].text != Wednesday")
      {
         var indexCounter;
         var days=document.form1.theDay;
         var lastoption=new option();
         days.options[6]=lastoption;
         for (indexCounter=6; indexCounter>2; indexCounter--)
             {
                days.options[indexCounter].text=days.options[indexCounter-1].text;
                days.options[indexCounter].value=days.options[indexCounter-1].value;
              }
          var option=new option ("Wednesday",2);
          days.options[2]=option;
        }
    else
       {
           alert("Do you want to have TWO Wednesdays?????");
        }
}
</script>
</head>
<body>
<form name=form1>
<select name=theDay size=5>
  <option value=0 selected>Monday
  <option value=1>Tuesday
  <option value=2>Wednesday
  <option value=3>Thursday
  <option value=4>Friday
  <option value=5>Saturday
  <option value=6>Sunday
</select>

<input type="button" value="Remove Wednesday" name=butRem onclick="butRemoveWed_onclick()">
<input type="button" value="Add Wednesday" name=butAd onclick="butAddWed_onclick()">


</form>
</body>
</html>        


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

7条回答 默认 最新

相关推荐 更多相似问题