我知道這很簡單,我需要在Google中搜索。我盡力而爲,找不到更好的解決方案。我有一個表單域,它需要一些輸入和一個選擇域,它有一些值。它還具有「其他」價值。如何根據選擇值顯示錶單輸入字段?
我要的是:
如果用戶選擇了「其他」選項,文本字段指定爲「其他」應顯示。當用戶選擇另一個選項(比'其他'),我想再次隱藏它。我如何使用JQuery執行該操作?
這是我的JSP代碼
<label for="db">Choose type</label>
<select name="dbType" id=dbType">
<option>Choose Database Type</option>
<option value="oracle">Oracle</option>
<option value="mssql">MS SQL</option>
<option value="mysql">MySQL</option>
<option value="other">Other</option>
</select>
<div id="otherType" style="display:none;">
<label for="specify">Specify</label>
<input type="text" name="specify" placeholder="Specify Databse Type"/>
</div>
現在我想說明DIV標籤**(ID = 「OTHERTYPE」)**僅當用戶選擇其他。 我想試試JQuery。這是我試過的代碼
<script type="text/javascript"
src="jquery-ui-1.10.0/tests/jquery-1.9.0.js"></script>
<script src="jquery-ui-1.10.0/ui/jquery-ui.js"></script>
<script>
$('#dbType').change(function(){
selection = $('this').value();
switch(selection)
{
case 'other':
$('#otherType').show();
break;
case 'default':
$('#otherType').hide();
break;
}
});
</script>
但是我無法得到這個。我該怎麼辦?由於
這個解決方案工作得也很好:HTTP://stackov erflow.com/a/29321711/5925104 – 2017-02-11 23:21:15