Javascript 如果在下拉列表中选择了某个项目,如何创建文本框?
我有一个下拉列表,其中包含以下值:Javascript 如果在下拉列表中选择了某个项目,如何创建文本框?,javascript,php,jquery,laravel-4,aramex,Javascript,Php,Jquery,Laravel 4,Aramex,我有一个下拉列表,其中包含以下值: <option>Aramex</option> <option>DHL</option> <option>FedEx</option> <option>Other</option> Aramex 敦豪环球速递公司 联邦快递 其他 当用户选择“其他”时,我想显示一个文本框。我该怎么做 我正在使用Laravel 4.2的一种方法: <script type="
<option>Aramex</option>
<option>DHL</option>
<option>FedEx</option>
<option>Other</option>
Aramex
敦豪环球速递公司
联邦快递
其他
当用户选择“其他”时,我想显示一个文本框。我该怎么做
我正在使用Laravel 4.2的一种方法:
<script type="text/javascript>
// Function to on change of the <select>, display the other input box
$(document).ready(function(){
$("#choices").on("change"),function(){
if($("#choices').val() == "Other"){
$("#otherinput").show();
}else{
$("#otherinput").hide();
}
});
});
</script>
<!-- hide the input box initially -->
<style>
#otherinput{display: none;}
</style>
<!-- These must have values since they're options, FYI, but set an ID for select and add values to options -->
<select id='choices'>
<option value='Aramex'>Aramex</option>
<option value='DHL'>DHL</option>
<option value='FedEx'>FedEx</option>
<option value='Other'>Other</option>
</select>
<!-- hidden until you select other option within the <select> -->
<input type='text' name='textinput' id='otherinput' />
一种方法:
<script type="text/javascript>
// Function to on change of the <select>, display the other input box
$(document).ready(function(){
$("#choices").on("change"),function(){
if($("#choices').val() == "Other"){
$("#otherinput").show();
}else{
$("#otherinput").hide();
}
});
});
</script>
<!-- hide the input box initially -->
<style>
#otherinput{display: none;}
</style>
<!-- These must have values since they're options, FYI, but set an ID for select and add values to options -->
<select id='choices'>
<option value='Aramex'>Aramex</option>
<option value='DHL'>DHL</option>
<option value='FedEx'>FedEx</option>
<option value='Other'>Other</option>
</select>
<!-- hidden until you select other option within the <select> -->
<input type='text' name='textinput' id='otherinput' />
以下是正确的修复方法:
<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';
else document.getElementById('div1').innerHTML='';
}
</script>
<select name="travel_arriveVia" id="travel_arriveVia" onchange="showfield(this.options[this.selectedIndex].value)">
<option selected="selected">Please select ...</option>
<option value="DHL">DHL</option>
<option value="Aramex">Aramex</option>
<option value="FedEx">FedEx</option>
<option value="Other">Other</option>
</select>
<div id="div1"></div>
函数显示字段(名称){
if(name='Other')document.getElementById('div1')。innerHTML='Other:';
else document.getElementById('div1')。innerHTML='';
}
请选择。。。
敦豪环球速递公司
芳纶
联邦快递
其他
以下是正确的修复方法:
<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';
else document.getElementById('div1').innerHTML='';
}
</script>
<select name="travel_arriveVia" id="travel_arriveVia" onchange="showfield(this.options[this.selectedIndex].value)">
<option selected="selected">Please select ...</option>
<option value="DHL">DHL</option>
<option value="Aramex">Aramex</option>
<option value="FedEx">FedEx</option>
<option value="Other">Other</option>
</select>
<div id="div1"></div>
函数显示字段(名称){
if(name='Other')document.getElementById('div1')。innerHTML='Other:';
else document.getElementById('div1')。innerHTML='';
}
请选择。。。
敦豪环球速递公司
芳纶
联邦快递
其他
hanks man,但我对“样式”部分有疑问,我应该把它放在哪里?通常,没有标记的代码放在.css文件中,然后被包含在HTML标记中。如果你是在HTML文件中完成的,把它放在headhanks man中,但是我有一个问题,“样式”部分应该放在哪里?一般来说,没有标记的代码放在一个.css文件中,然后被包含在你的HTML标记中。如果您是在HTML文件本身中进行的,请将其转储到Head中。也许您没有简单的升级方法,但我希望您知道Laravel 4.2非常旧,不是LTS版本。该分支的安全更新在2年前停止。@Fx32我试图将其升级到Laravl 5.4,但我是初学者,面临许多问题,所以我放弃了。也许您没有简单的升级方法,但我希望您知道Laravel 4.2非常旧,不是LTS版本。该分支的安全更新在2年前停止。@Fx32我试图将其升级到Laravl 5.4,但我是初学者,面临许多问题,所以放弃了