0

ユーザーがドロップダウンボックスの値から選択した内容に応じて、ページをリダイレクトしたり、テキストボックスを表示/非表示にしたりするJavaScriptのswitch caseステートメントがあります。Firefox では正常に動作しますが、IE では正常に動作しません。エラー メッセージは次のとおりです: SCRIPT5007: プロパティ 'value' の値を取得できません: オブジェクトが null または未定義の _index.htm、行 67 文字 7

switch (document.form.description.options[description.selectedIndex].value) - IE は form.desciprition で苦労しています。

<script language="javascript">
 function fundsource()
   {
       var val;


       for (i=0; i< document.form.description.length; i++)
       {

            switch (document.form.description.options[description.selectedIndex].value)

            {
                case "Select":
                    document.form.scholarship.style.visibility='hidden';
                    document.form.description_other.style.visibility='hidden';
                    break;
                case "Wall of Friends":
                    location.href= some url
                    break;
                case "Scholarship":
                    document.form.scholarship.style.visibility='visible';


                    break;
                case "Other":
                    document.form.description_other.style.visibility='visible';
                    document.getElementById("descriptionspan").style.visibility="visible";
                    break;


            }
       }
   }
</script>

以下のようなhtmlコード:

<tr>
                    <td align="right">Description of the Fund for Your Donation <br /></td>
                    <td>

        <select name="description" id="description" onchange="fundsource()">
                        <option>Select</option>
                        <option>Scholarship</option>
                        <option>Rainbow of Life</option>
                        <option>Wall of Friends</option>
                        <option>General</option>
                        <option>Other</option>

                    </select>
                    <select name="scholarship" id="scholarship" style="visibility:hidden;">
                        <option>Alumni Scholarship</option>
                        <option>Other</option>
                    </select>
                    </td>
                  </tr>
                   <tr>
                    <td align="right" valign="top"><div id="descriptionspan" alt="description" style="visibility:hidden;">Other, please specify:</div></td>
                    <td><input type="text" name="description_other" size="50" alt="Fund Other" style="visibility:hidden;" /></td>
                  </tr>

document.form.description.options[description.selectedIndex].value を document.form.description.options[description.selectedIndex].text に変更しましたが、まだ機能しません。お知らせ下さい。ティア。

4

3 に答える 3

0

私が知っているように、つまりフリークです。それを知らせるためにもっと単語を入力する必要があります

1.js コードを変更します。

switch (document.form.description.options[description.selectedIndex].value)

switch (document.form.description.options[document.form.description.selectedIndex].value)

2.html コードを変更する

<option>Select</option>
<option>Scholarship</option>
<option>Rainbow of Life</option>
<option>Wall of Friends</option>
<option>General</option>
<option>Other</option>

<option value="Select">Select</option>
<option value="Scholarship">Scholarship</option>
<option value="Rainbow of Life">Rainbow of Life</option>
<option value="Wall of Friends">Wall of Friends</option>
<option value="General">General</option>
<option value="Other">Other</option>

属性を追加したくない場合はvalue、js.valueを次のように変更する必要があります。.innerText

于 2013-05-15T14:02:32.527 に答える