好的,我看到您的问题有两种解决方案。第一个是实时值更新:
<select id="folder" name="folder">
<option ...
... </option>
<option id="otheroption" value="New">Other</option>
</select>
<div id="otherfolder" style="display:none">
<label for="otherinput">New folder name:</label>
<input id="otherinput">
</div>
<script> // here, or execute the following onload/ondomready
document.getElementById("folder").onchange = function(e) {
// I guess you have this piece of code already
document.getElementById("otherfolder").style.display =
this.options[this.selectedIndex].id == "otheroption" ? "" : "none";
};
document.getElementById("otherinput").onkeyup = function(e) {
document.getElementById("otheroption").value = this.value;
};
</script>
第二种方法是动态更改name
选择框和输入框的 s(使用完全相同的标记),以确定将哪个值作为folder
参数发送到服务器:
document.getElementById("folder").onchange = function(e) {
var name = "folder",
other = this.options[this.selected].id == "otheroption";
document.getElementById("otherfolder").style.display = other ? "" : "none";
document.getElementById("otherinput").name = other ? name : "";
this.name = other ? "" : name;
};