我有一个包含以下行的Jsp文件:

<s:select list="list" name="message" id="selectMsg"></s:select>
<div id="txtMessage" style="display:none">
   <h3>
      <span id="txtMessage" style="margin-left: 230px">
          Message: <s:textarea name="message" placeholder="Message"/>
      </span>
   </h3>
</div>


行动:

public String warn() throws Exception {
    WarnDAO dao = new WarnDAO();

    AccountDAO accdao = new AccountDAO();
    acc = accdao.getAccountByUsername(username);

    List<WarningMessage> warningMessage = dao.showMsg();
    list = new ArrayList<String>();
    for (WarningMessage warningMessage1 : warningMessage) {
        list.add(warningMessage1.getMessage());
    }
    list.add("Other");


    warning_msg_DAO wmDAO = new warning_msg_DAO();
    wm = wmDAO.getByMessage(message);

    DateFormat dateFormat = new SimpleDateFormat("hh:mm a dd/MM/yyyy");
    Date date = new Date();
    System.out.println(dateFormat.format(date));
    WarningAccount warningAcc = new WarningAccount();
    warningAcc.setWarnedaccount(acc);
    warningAcc.setMessage(message);
    warningAcc.setDay(date);

    dao.warn(warningAcc);
    return "success";
}


在s:中,选择包含选项“其他”。当用户选择“其他”时,将显示文本区域,并允许用户输入自己的消息。有什么解决办法吗?

最佳答案

function toggleOther(val){
    document.getElementById("other").style.display = (val=="other") ? "block" : "none";
}

<select onchange="toggleOther(this.value);">
    <option value="foo"  >________ FOO ________</option>
    <option value="bar"  >________ BAR ________</option>
    <option value="other">_______ OTHER ______</option>
</select>
<div id="other" style="display: none;">
    <textarea>I'm visible only when choosing OTHER</textarea>
</div>

07-26 07:45