【问题标题】:jquery ajax unhide div if variable equals如果变量等于,jquery ajax 取消隐藏 div
【发布时间】:2013-12-15 12:12:37
【问题描述】:
    <script>
$(document).ready(function(){
 var currentsize = $('option:selected', $('select#size')).val();
    $.ajax({
        type: \"post\",
        url: \"tshirt_ajax.php?checkshop=$shopid&checkproducttype=$producttype&stockcolor=\" + $('#productColor$articleid').val() + \"&currentsize=\" + currentsize,
        success: function(data){
            $('select#size').html(data);
   $('#size').coreUISelect();
   $('#quantity').coreUISelect();
  }
    });

   $('a.colorlink').click(function(e){
 e.preventDefault();
    var stockcolor = $(this).attr('id'),
        checkshop = $shopid,
        checkproducttype = $producttype;

    $.ajax({
        type: \"post\",
        url: \"tshirt_ajax.php?checkshop=\" + checkshop + \"&checkproducttype=\" + checkproducttype + \"&stockcolor=\" + stockcolor + \"&currentsize=\" + currentsize,
        beforeSend: function(){
            $('#productColor$articleid').val(stockcolor);
        },
        success: function(data){
            $('select#size').html(data);
        $('#tshirtimg').attr('src', '$http://www.ni-dieu-ni-maitre.com/images/".$productid."_' + stockcolor + '_2/t-shirt-couleur.png');
        $('#ex1 .zoomImg').attr('src', '$http://www.ni-dieu-ni-maitre.com/images/".$productid."_' + stockcolor + '_2/t-shirt-couleur.png');
   $('#size').coreUISelect('update');
        }
    });

    });

 $('select#size').change(function(){
  currentsize = $('option:selected', this).val();
 });

});
</script>

我也有以下div:

<div class='etiquettedescription_content' style='display:none;'>

在上面的脚本中,我想添加以下命令:

我正在尝试修改上面的脚本,因此当单击“a.colorlink”时,我想取消隐藏 div,但前提是单击的 stockcolor 对应于 1、351、63 或 16

知道我该怎么做吗?

【问题讨论】:

    标签: javascript php jquery css ajax


    【解决方案1】:

    如果我正确理解你的问题,那么试试这个:

    $('a.colorlink').click(function(e){
     e.preventDefault();
        var stockcolor = $(this).attr('id'),
            checkshop = $shopid,
            checkproducttype = $producttype;
            if( stockcolor==="1" || stockcolor==="351" stockcolor==="63" stockcolor==="16"  ){
                $(".etiquettedescription_content").show();
            }else{
                $(".etiquettedescription_content").hide();
            }
            .....
    

    【讨论】:

      【解决方案2】:

      如果我误解了你的问题,对不起。

      在 $('a.colorlink').click 事件处理程序中,添加

      if(stockcolor == 1 || ... other values) {
          $('.etiquettedescription_content').css('display', 'block');
      }
      

      【讨论】:

        猜你喜欢
        • 2018-12-31
        • 2012-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-15
        • 1970-01-01
        相关资源
        最近更新 更多