请问在JSP中,选中下拉框中的“其他”这个选项时,怎么实现能够在文本框中编写文字?


下拉框选项是由这种业务字典的方式产生的,要求只在触发“其他”选项是用户能够自己添加内容。之前没有学过JSP,想请答主最好能给出代码

js就可以实现,可以参考下:https://blog.csdn.net/xiaodongge521/article/details/83011554

记得引入jquery


<select  name="type" onchange="changeType(this)">
    <option value="1">选项A</option>
    <option value="2">选项B</option>
    <option value="3">其他</option>
</select>
<input type="text" id="inputText" style="display:none;"/>


function changeType(tag){
    var currentSelectVal = $(tag).val();

    if(currentSelectVal == '3'){
        $("#inputText").show()
    }else{
        $("#inputText").hide()
    }
}

function show(obj) { document.getElementById("other").style.display=(obj.value==0)?"":"none" }


订购厂家:

南京林业养殖基地
其他订购厂家


Integer dgcj = Integer.parseInt(request.getParameter("dgcj"));
if (dgcj == 1 && dgcj !=null) {
    animal.set("ordering_manufacturer","南京林业养殖基地");
}else{
    animal.set("ordering_manufacturer",request.getParameter("other"));
}