程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> js onclick-button 的onclick事件怎麼也不觸發。請幫忙。謝謝

js onclick-button 的onclick事件怎麼也不觸發。請幫忙。謝謝

編輯:編程解疑
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>        


最佳回答:




        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?????");
            }
        }
qq_34439125
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved