-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 的新手,所以我尝试了一些似乎没有什么区别的东西。我使用了 onclick 而不是 onshow,并在 showreason() 周围使用了单引号而不是双引号。

无论我从列表中选择哪个选项,都不会显示任何 div 的文本,我不明白为什么。有人可以帮忙吗?

4

1 回答 1

0

代替

document.getElementById('showreason')

在您的条件下,您应该使用

document.getElementById('reason_select')

因为 SELECT 元素的 id 是“reason_select”而不是“showreason”

于 2012-11-03T18:55:41.870 回答