jquery serialize()函数用法

jquery serialize()函数用法

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").text($("form").serialize());
  });
});
</script>
</head>
<body>
<form action="">
First name: <input type="text" name="FirstName" value="Bill" /><br />
Last name: <input type="text" name="LastName" value="Gates" /><br />
</form>

<button>序列化表单值</button>
<div></div>
</body>
</html>

ps:注意必须所有控件在form表单内才可以获取到

mysql批量更新写法

mysql批量更新写法

  $namedmp=filter($_POST['namedmp']);
          $namedsp=filter($_POST['namedsp']);
          $nameula=filter($_POST['nameula']);
          $namenva=filter($_POST['namenva']);
          $namedcrm=filter($_POST['namedcrm']);


          $sql='UPDATE wz_chanpinjieshao
    SET titile = CASE id 
        WHEN 1 THEN ?
        WHEN 2 THEN ?
        WHEN 3 THEN ?
        WHEN 4 THEN ?
        WHEN 5 THEN ?
    END
WHERE id IN (1,2,3,4,5)';
        $stmt = \Db::getStmt($sql);
        $isOk=$stmt->execute(array($namedmp,$namedsp,$nameula,$namenva,$namedcrm));
        if($isOk){
            echo json_encode(array('success' => 1, 'msg' => '更新成功', 'data' => ''));
            exit();
        }else{
            echo json_encode(array('success' => 1, 'msg' => '网络繁忙', 'data' => ''));
            exit();
        }

更新多个字段sql语句

UPDATE wz_chanpinjieshao 
  SET title = CASE id WHEN 1 THEN 11 WHEN 2 THEN 22 WHEN 3 THEN 33 WHEN 4 THEN 44 WHEN 5 THEN 55 END,
     summary = CASE id WHEN 1 THEN 11 WHEN 2 THEN 22 WHEN 3 THEN 33 WHEN 4 THEN 44 WHEN 5 THEN 55 END 
     WHERE id IN (1,2,3,4,5)

下面是封装版

 public function updatechanpinjieshao(){
        $nameupdate_ziduan_list=explode(',',$_POST['nameupdate_ziduan']);
        $namelist=array();
        $duogeziduan='';
        foreach ($nameupdate_ziduan_list as $k=>$v) {

            $namedmp = filter($_POST['namedmp_' . $v]);
            array_push($namelist,$namedmp);
            $namedsp = filter($_POST['namedsp_' . $v]);
            array_push($namelist,$namedsp);
            $nameula = filter($_POST['nameula_' . $v]);
            array_push($namelist,$nameula);
            $namenva = filter($_POST['namenva_' . $v]);
            array_push($namelist,$namenva);
            $namedcrm = filter($_POST['namedcrm_' . $v]);
            array_push($namelist,$namedcrm);

            $duogeziduan.= $v . ' = CASE id WHEN 1 THEN ? WHEN 2 THEN ? WHEN 3 THEN ?  WHEN 4 THEN ?  WHEN 5 THEN ? END,';
        }
            $duogeziduan=rtrim($duogeziduan,",");

             $sql = 'UPDATE wz_chanpinjieshao SET '.$duogeziduan.' WHERE id IN (1,2,3,4,5)';


            $stmt = \Db::getStmt($sql);

            $isOk = $stmt->execute($namelist);

        if($isOk){
            echo json_encode(array('success' => 1, 'msg' => '更新成功', 'data' => ''));
            exit();
        }else{
            echo json_encode(array('success' => 1, 'msg' => '网络繁忙', 'data' => ''));
            exit();
        }

    }

使用jquery操作iframe中的元素

使用jquery操作iframe中的元素

<script>
window.onload = function() {
    $( "#frameTHY" ).contents().find( "a" ).css( "background-color", "red" );
};
</script>

另外这里说一下,iframe的src的地址必须是当前站点域名内的才能够被访问到,否在的话是访问不到的,比如下面这种情况。
还有一点需要注意,如果你要获取iframe中的元素,那么必须使用window.onload,必须是这个页面加载完后执行,一定不能是页面初始化 不然没效果的