我正在开发一个项目,它将使用大量选择菜单输入各种数据.我想直接在select中包含一个'other'选项,它将触发一个简单的对话框,并允许用户输入一个自定义值(如果适用),类似于以下javascript代码:
<script type="text/javascript" language="javascript">
function chkother(fld,len,idx) {
if ((idx+1)==len) {
other=prompt("Please indicate 'other' value:");
fld.options[idx].value=other;
fld.options[idx].text=other;
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
适用于选择:
<select onchange="chkother(this,this.options.length,this.options.selectedIndex)" name="example" id="example" class="formSelect">
<option value=""></option>
<option value="yes">yes</option>
<option value="no">no</option>
<option value="other">other</option>
</select>
Run Code Online (Sandbox Code Playgroud)
并显示一个提示,它将使用用户文本更新选项.
我想使用jquery做类似的事情,所以我可以看看扩展功能和学习一些jquery,但是我开始时遇到了麻烦.