yii 2.0 ajax 的即点即改 多条件搜索

<tr>  
<td>商品</td>
</tr>
<tr>
  <td><span class="click" id="<?php echo $v['id']?>"><?php echo $v['goods']?></span></td>
</tr>
jquery
  $(function(){
        $(document).on("click",".click",function(){
           var id=$(this).attr('id');//获取id
            var aa=$(this).html();//获取html值
          //  alert(aa)
        $(this).parent().html("<input type=\"text\" value="+aa+" class='one'>");//通过当前获取父节点的值
            $(".one").focus();//聚焦事件
            $(".one").blur(function(){//鼠标离开事件
                _this=$(this);
               var  bb=$(this).val();//获取新值
            //    alert(bb);
                $.post("?r=lianxi/pi",{id:id,bb:bb},function(msg){
                   // alert(msg)
                   if(msg==1){
                     _this.parent().html("<span class=\"click\" id="+id+">"+bb+"</span>");
                   }else{
                      alert("失败");
                   }
            })

            })
        })
    })
控制器
    public  function actionPi(){
        $id=\yii::$app->request->post('id');
        $bb=\yii::$app->request->post('bb');
        $result=shang::find()->where(['id'=>$id])->one();
     //   print_r($result);die;
        $result->goods=$bb;
        $re=$result->save();
      //  print_r($re);die;
        if($re){
            return  1;
        }else{
            echo 0;
        }
 }
yii2.0多条件搜索
<tr>
    <td colspan="2">名称:<input type="text" id="search1"></td>
    <td colspan="2">排序:<input type="text" id="search2"> </td>
    <td><input type="button" value="搜一搜" id="btn"></td>
</tr>
 $(function(){
        $("#btn").click(function(){
            var search1 = $("#search1").val();
            var search2 = $("#search2").val();
            //发送AJAX请求
            $.ajax({
                url:"?r=lianxi/search",
                data:{search1:search1,search2:search2},
                type:"POST",
                success:function(msg) {

                    msg= eval(msg);
                    var str="<tr>" +
                        "<td>编号</td>"+
                        "<td>名称</td>"+
                        "<td>货号</td>"+
                        "<td>排序</td>"+
                        "<td>库存</td>"+
                        "<td>图片</td>"+
                        "<td>上架</td>"+
                        "<td>热销</td>"+
                        "</tr> ";
                    for(var i=0;i<msg.length;i++){
                        str+="<tr>" +
                        "<td>"+msg[i].id+"</td>" +
                        "<td>"+msg[i].goods_name+"</td>" +
                        "<td>"+msg[i].money+"</td>" +
                        "<td>"+msg[i].paixu+"</td>" +
                        "<td>"+msg[i].kucun+"</td>" +
                        "<td><img src="+msg[i].filename+" height='50' width='50'/>";
                        if(msg[i].shangjia==1){
                            str+="<td>√<td>"
                        }else{
                            str+="<td>错<td>"
                        }
                        if(msg[i].rexiao==1){
                            str+="<td>√<td>"
                        }else{
                            str+="<td>错<td>"
                        }
                        str+="</tr>";
                    }
                    $('.tab').html(str);
              }
            })
        })
    })
控制器
    $search1=\yii::$app->request->post('search1');
    $search2=\yii::$app->request->post('search2');
    //print_r($search2);die;
    $where=1;
    if(!empty($search1)){
        $where .= " and goods_name like '%$search1%'";
    }
    if(!empty($search2)){
        $where .= " and paixu like '%$search2%'";
    }
    $blogInfo = goods::find()->where($where)->asArray()->all();
    //搜索后关键字标红
    foreach($blogInfo as $key => $value) {
        $blogInfo[$key]['goods_name'] = str_replace($search1, "<font color='red'>$search1</font>", $value['goods_name']);
        $blogInfo[$key]['paixu'] = str_replace($search2, "<font color='red'>$search2</font>", $value['paixu']);
    }
    echo json_encode($blogInfo);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值