-1

ドロップダウンに省略された選択肢を表示したいが、下に全文を表示したい選択リストがあります。「その他」がオプションとして選択されたときにテキスト入力を表示するために以前に使用したjavascriptを変更しようとしています。select、div、および javascript は、php で動的に生成されます。問題が本当にこのコードであることを確認するために、php で生成されたコードをプレーンな html ファイルにカット アンド ペーストしました。

次のスクリプトがあります。

     <script type="text/javascript">  
                function showreason() { if (document.getElementById('showreason').value == 'BLANK') { 
document.getElementById('showreasonBLANK').style.display = 'block' ;
} else {
        document.getElementById('showreasonBLANK').style.display = 'none';
    } if (document.getElementById('showreason').value == 'RECAP') { 
document.getElementById('showreasonRECAP').style.display = 'block' ;
} else {
        document.getElementById('showreasonRECAP').style.display = 'none';
    } if (document.getElementById('showreason').value == 'RETIRE') { 
document.getElementById('showreasonRETIRE').style.display = 'block' ;
} else {
        document.getElementById('showreasonRETIRE').style.display = 'none';
    } if (document.getElementById('showreason').value == 'ALTERN') { 
document.getElementById('showreasonALTERN').style.display = 'block' ;
} else {
        document.getElementById('showreasonALTERN').style.display = 'none';
    } if (document.getElementById('showreason').value == 'EXPAND') { 
document.getElementById('showreasonEXPAND').style.display = 'block' ;
} else {
        document.getElementById('showreasonEXPAND').style.display = 'none';
    }} 
function selection(select) {
    document.getElementById("section_" + select.value).style.display = "block";
}
            </script> 

これは本体にあります:

    <SELECT NAME="showreason"  id="reason_select"  onchange="showreason()" >
<OPTION  VALUE="BLANK"> Omit Reason </OPTION>
<OPTION  VALUE="RECAP"> Recapitalization </OPTION>
<OPTION  VALUE="RETIRE"> Retirement </OPTION>
<OPTION  VALUE="ALTERN"> So owners can pursue other alternatives </OPTION>
<OPTION  VALUE="EXPAND"> To allow the business to grow </OPTION></select>
</p>
<div id="showreasonBLANK" style="display: none;"></div>
<div id="showreasonRECAP" style="display: none;">A recapitalization will allow current ownership to diversify holdings without compromising the company's flexibility to finance growth.</div>
<div id="showreasonRETIRE" style="display: none;">The business is being sold for retirement.</div>
<div id="showreasonALTERN" style="display: none;">While this business is attractive the current ownership is looking to concentrate on other business opportunities.</div>
<div id="showreasonEXPAND" style="display: none;">Current ownership believes that a new owner will be able to grow the business faster and take it to a new level.</div>

私はjavascriptが初めてなので、違いがないように見えるいくつかのことを試しました。onshow の代わりに onclick を使用し、showreason() の周りに二重引用符の代わりに単一引用符を使用しました。

リストからどのオプションを選択しても、どの div のテキストも表示されず、理由がわかりません。誰か助けてくれませんか?

4

1 に答える 1

0

それ以外の

document.getElementById('showreason')

あなたの条件では、使用する必要があります

document.getElementById('reason_select')

SELECT 要素の ID が「showreason」ではなく「reason_select」であるため

于 2012-11-03T18:55:41.870 に答える