当从组合中选择特定选项时自动隐藏文本框 [英] autohide text box when a particular option is selected from combo

查看:107
本文介绍了当从组合中选择特定选项时自动隐藏文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,当选择第二或第三选项时显示一个文本框,但是当第一个选项被选中时如何隐藏该文本框?

<$ p $ ($ {
$ comboame:this.value
($'$ combo.jsp',{
$' },function(data){
if(data.isTrue){
$(#textbox)。empty()。append(< input type ='text'id ='text1' />); //显示一个空文本框
}
else {
//如何清除该文本框并隐藏它?
}
} );
});

html

 < select id =comboname =comboname> 
< option value =_>< / option> //当这个选项是
时,如何清除和隐藏文本框?
< option value =somevalue> somename< / option> //当选择此选项时,它
显示一个空文本框
< option value =somevalue1> ; somename1< / option>当这个选项被选中时,它也是
显示相同的空文本框
< / select>
//在下面的div中,正在显示文本框
< div id =textbox>
//当从上面的组合
< / div>中选择第二或第三选项时,显示文本框。

服务器端(combo.jsp)

  JSONObject jsonObj = new JSONObject(); 
jsonObj.put(isTrue,true);
response.setContentType(application / json);
response.getWriter()。write(jsonObj.toString());


解决方案

您真的需要服务器端吗?这里没有例子:

  $(#combo)。change(function(){
if(this 。); $ b $(#textbox)。empty()。append(< input type ='text'id ='text1'/>);
}
else {
$(#textbox)。hide();
}
});

另请参阅 isTrue >
>有条件的。


I have one combo box which displays a text box when 2nd or 3rd option is selected, but how to hide that text box when first option is selected?

$("#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>

server side (combo.jsp)

JSONObject jsonObj= new JSONObject(); 
 jsonObj.put("isTrue","true");
response.setContentType("application/json");
response.getWriter().write(jsonObj.toString());

解决方案

Do you really need server side? Here an example without:

$("#combo").change(function () {
    if (this.value != '_') {  
        $("#textbox").empty().append("<input type='text' id='text1'/>");
    }
    else {
        $("#textbox").hide();
    }
});

Also see this example.

But if really need server side, you have to set isTrue conditionally.

这篇关于当从组合中选择特定选项时自动隐藏文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆