0

jqueryでチェックするドロップダウンがあり、特定の値が選択されている場合は、入力ボックスが表示されます。選択した値を配列と比較する必要があります。選択が配列内の値の1つと一致する場合は、その値を非表示フィールドのタグに追加する必要があります。私のjqueryの知識はほとんどないので、アドバイスをいただければ幸いです。

私の現在のコード:(データベースにクエリを実行して、トレッカーのすべての子の値を取得します。これが私の配列になります)

<script type="text/Javascript">
        jQuery(function ($){
            $(document).ready(function () {
                    $(".kw").hide();
                });

            $(function(){
                $('.postform').change(function() {
                    var selectData = $(this).attr("data-select");
                    var selectValue = $(this).val();
                    $('.kw').hide();
                     if($("fieldset[data-select='" + selectData + selectValue +"']").css("display") == "none"){
                         $("fieldset[data-select^='" + selectData + "']").hide();
                         $("fieldset[data-select='" + selectData + selectValue +"']").show();
                     }
                });
            });
        });
        </script>

<form role="search" method="get" id="equipfilter" action="">
 <fieldset>
  <select name="exc_equipment_cat" id="exc_equipment_cat" class="postform" data-select="select1">
    <option class="level-0" value="allerlei">Allerlei&nbsp;&nbsp;(10)</option>
    <option class="level-0" value="implemente">Implemente&nbsp;&nbsp;(97)</option>
    <option class="level-1" value="balers-toebehore">&nbsp;&nbsp;&nbsp;Balers &amp; Toebehore&nbsp;&nbsp;(4)</option>
    <option class="level-1" value="disse">&nbsp;&nbsp;&nbsp;Disse&nbsp;&nbsp;(4)</option>
    <option class="level-1" value="hammermeule">&nbsp;&nbsp;&nbsp;Hammermeule&nbsp;&nbsp;(4)</option>
    <option class="level-1" value="ploee">&nbsp;&nbsp;&nbsp;Ploeë&nbsp;&nbsp;(11)</option>
    <option class="level-1" value="ripper">&nbsp;&nbsp;&nbsp;Ripper&nbsp;&nbsp;(8)</option>
    <option class="level-0" value="trekkers">Trekkers&nbsp;&nbsp;(43)</option>
    <option class="level-1" value="case">&nbsp;&nbsp;&nbsp;Case&nbsp;&nbsp;(4)</option>
    <option class="level-1" value="fiat">&nbsp;&nbsp;&nbsp;Fiat&nbsp;&nbsp;(5)</option>
    <option class="level-1" value="ford">&nbsp;&nbsp;&nbsp;Ford&nbsp;&nbsp;(1)</option>
    <option class="level-1" value="john-deere">&nbsp;&nbsp;&nbsp;John Deere&nbsp;&nbsp;(13)</option>
    <option class="level-1" value="landini">&nbsp;&nbsp;&nbsp;Landini&nbsp;&nbsp;(5)</option>
    <option class="level-1" value="massey-ferguson">&nbsp;&nbsp;&nbsp;Massey Ferguson&nbsp;&nbsp;(3)</option>
    <option class="level-1" value="mccormick">&nbsp;&nbsp;&nbsp;McCormick&nbsp;&nbsp;(4)</option>
    <option class="level-1" value="new-holland">&nbsp;&nbsp;&nbsp;New Holland&nbsp;&nbsp;(8)</option>
 </select>
</fieldset>
<fieldset class="kw" data-select="select1 WHERE VALUE SHOULD BE ADDED" style="display: none;">
  <legend>Kw Range:</legend>
  <input type="text" name="kw_min" placeholder="min" value=""><br>
  <input type="text" name="kw_max" placeholder="max" value="">
 </fieldset>
 <fieldset>
  <legend>Price Range:</legend>
  <input type="text" name="pr_min" placeholder="from" value=""><br>
  <input type="text" name="pr_max" placeholder="to" value="">
 </fieldset>
<input type="submit" id="filtersubmit" value="Search">
</form>

これはこの質問への回答です

4

2 に答える 2

1

これがあなたに役立つことを願っています

var values = ['a', 'b', 'c'];
jQuery('your-selector-to-select').change(function(){
    var j = jQuery(this);
    if(values.indexOf(j.val()) >= 0) {
        jQuery('hidden-selector').val(j.val());
    }
});

最初の質問への回答:

jQuery('your-fieldset-selector').attr('data-select', 'select1 ' + j.val());
于 2012-11-26T08:40:06.667 に答える
0

inArray(value,array) を使用して配列を検索し、一致する index を取得します。

var yourarray = ['value1','value2'];
$('.matchedindex').text($.inArray($('.search').val(),yourarray) ;

$('.search').val()value1 と等しい場合は$('.matchedindex').text()1 になります

または、配列内の検索に $.each を使用できます。

var flag=false;
$.each(array,function(i,value){
    if(value.search($('.search').val())!=-1){
    # search is matched # you have index and value of array
        flag=true;
    }
});
于 2012-11-26T08:43:56.487 に答える