简体   繁体   English

根据2个选择框中的2个值,通过jquery显示hide div

[英]Show hide div by jquery depending on 2 values from 2 selectbox

anybody can help me? 有人可以帮助我吗? I want to make show hide some div by jquery depending on values from two selectbox this my code 我想根据两个选择框的值通过jquery显示隐藏一些div这是我的代码

$("#offer_seeking_select").change(function(){
var offer_seeking=$(this).val();
var selectedCategory=$("select.category-select:visible").last().find("option:selected").val();

$.get(www_base+"adding.php?cID="+selectedCategory+"&offer="+offer_seeking,function(data){
if(data.status=="ok"){$("#forms").html(data.html).trigger("forms_content_updated")
}})});

html code HTML代码

<select id="drop-2"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<select id="drop-3"><option value="offer">Offer</option><option value="seeking">Seeking</option></select>
<div id="forms"></div>

and some 'div' in adding.php will be show hide in #forms depending on values when select from #drop-2 and drop-3, example if I select 1 from drop-2 and offer from drop-3 show #one and #three hide #two, else select 2 from drop-2 and seeking from drop-3 show #two and #three hide #one 从#drop-2和drop-3中选择值时,adding.php中的一些'div'将根据值显示为隐藏在#forms中,例如,如果我从drop-2中选择1并从drop-3中提供,则显示#one和#3隐藏#2,否则从drop-2中选择2,然后从drop-3中寻求显示#two和#3隐藏#one

this html in file adding.php because I can't get cID and offer in file adding.php 该文件添加html中的html,因为我无法获取cID并在文件添加php中提供

<div id="one">abc</div>
<div id="two">123</div>
<div id="three">789</div>

How about something like this which uses classes that correspond to the id of the select, you may need to refactor to fit your required logic as I a not sure I fully understood. 这样的事情使用与选择的id对应的类怎么样,您可能需要重构以适应所需的逻辑,因为我不确定我是否完全理解。

$('#foo, #bar').change(function(e) {
    var $elm = $(e.target);
    var $elmDiv = $('.' + $elm.attr('id'));

    if ($elm.val() !== "") {
        $elmDiv.show();
    } else {
        $elmDiv.hide();
    }
});​

here is a demo 这是一个演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM