我对JS相当陌生,我找到了一个脚本,当选择一个特定的选项(在本例中为'Other')时,它会在选择字段下面添加一个文本框,虽然我想要如果选择另一个选项并显示“朋友”,则显示相同框的选项。我怎样才能改变JS的一部分,它确定这一点,从我的理解是这部分Javascript语法查询
function showfield(name){
if(name=='Other')
,但我不知道正确的语法来执行此。我假设其有效像
if(name=='Other' or 'Friend')
anyhelp将不胜感激,谢谢。
这是当前的代码。
<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='<input type="text" name="other" class="text-field" placeholder="Please state.." />';
else document.getElementById('div1').innerHTML='';
}
</script>
<form id="quote" class="quote-form">
<input name="" class="text-field" type="text" placeholder="Full Name" />
<input name="" class="text-field" type="text" placeholder="Contact Number" />
<input name="" class="text-field" type="text" placeholder="E-Mail Address" />
<select name="referral" class="select-field" onchange="showfield(this.options[this.selectedIndex].value)">
<option selected="selected">Where did you hear about us? (Please select..)</option>
<option value="Checkatrade">Check-a-Trade</option>
<option value="MyBuilder">MyBuilder</option>
<option value="Friend">Referral from a friend (Please state below)</option>
<option value="Other">Other (Please state below)</option>
</select>
<div id="div1"></div>
隐藏它'如果(名称==“其他” || NAME = ='朋友')' – Pointy
我认为在javascript中使用'或'操作符的搜索功能比发布问题更简单。 –