1
我不知道如何使用下拉菜單外的點擊按鈕(可以是加號),而不是點擊「其他」,以便用戶可以輸入另一個值?謝謝!!如何在菜單外添加單擊按鈕以打開新的文本字段而不是單擊「其他」?
下面是HTML:
<form onsubmit="FormSubmit(this);">
<label for="last_name">Brand:</label>
<input type="hidden" name="brand" />
<select name="fruit_ddl" onchange="DropDownChanged(this);">
<option value="">--select--</option>
<option value="brand1">Brand1</option>
<option value="brand2">Brand2 </option>
<option value="brand3">Brand3</option>
<option value="">Other..</option>
</select> <input type="text" name="brand_txt" style="display: none;" />
<button type="submit">Add Brand</button>
</form>
的javascript:
function DropDownChanged(oDDL) {
var oTextbox = oDDL.form.elements["brand_txt"];
if (oTextbox) {
oTextbox.style.display = (oDDL.value == "") ? "" : "none";
if (oDDL.value == "")
oTextbox.focus();
}
}
function FormSubmit(oForm) {
var oHidden = oForm.elements["brand"];
var oDDL = oForm.elements["brand_ddl"];
var oTextbox = oForm.elements["brand_txt"];
if (oHidden && oDDL && oTextbox)
oHidden.value = (oDDL.value == "") ? oTextbox.value : oDDL.value;
}
您希望能夠動態地將'
感謝您的評論。是的,我想通過在菜單外添加一個具有相同功能的點擊按鈕來切換下拉菜單中的「其他」 –