我有一個組合框,當選擇第二或第三選項時顯示文本框,但是當第一個選項被選中時如何隱藏該文本框?當從組合框中選擇特定選項時自動隱藏文本框
$("#combo").change(function() {
$.getJSON('combo.jsp', {
comboname: this.value
}, function (data) {
if(data.isTrue){
$("#textbox").empty().append("<input type='text' id='text1'/>");// display an empty text box
}
else{
// how to clear that text box and hide it?
}
});
});
下面的HTML
<select id="combo" name="comboname">
<option value="_"></option>// how to clear and hide the text box when this option is
selected?
<option value="somevalue">somename</option>// when this option is selected then it
displays an empty text box
<option value="somevalue1">somename1</option>when this option is selected then it also
displays the same empty text box
</select>
// in the following div, text box is being displayed
<div id="textbox">
// here text box is displayed when option 2nd or 3rd is selected from the above combo
</div>
服務器端(combo.jsp)
JSONObject jsonObj= new JSONObject();
jsonObj.put("isTrue","true");
response.setContentType("application/json");
response.getWriter().write(jsonObj.toString());
數據「應該」是一個基於您的內容類型的json對象它可能不是?在if語句上方的返回函數中嘗試console.log(data)(如果它只返回一個字符串),您可能需要使用jQuery.parseJSON(data)才能像對象一樣訪問響應。 – 2012-02-21 08:24:19
@j_mcnally米錯在這裏:http://stackoverflow.com/questions/9377544/returning-sum-from-server-side-by-json – Phillipa 2012-02-21 12:30:54