jquery写即点即改问题
jquery写的一些问题供大家参考yii框架上面的
视图层------------------------------------
<?php
use yiiwidgetsLinkPager;
use yiihelpersHtml;
?>
form表单里的一些关键的取点-------------------
<td id="<?=$v["id"]?>">
<span class="gai">
<?=$v["content"]?>
</span>
</td>
// 即点即改
$(function () {
$(".gai").click( function () {
// alert(444)
_this=$(this).text();
// alert(_this);
$(this).parent().html("<input type="text" class="nb" value="+_this+"/>")
});
// 事件委托
$(document).on("blur", ".nb", function(){
var content=$(this).val();
var id=$(this).parent().attr("id");
// alert(id);
$.ajax({
type: "get",
url: "?r=xinwen/gai",
data:{
id:id,
content:content
},
success: function(msg){
alert(msg);
}
});
});
})
我们习惯在php后台太处理使用修改根据Id修改
public function actionGai()
{
$request = Yii::$app->request;
$content=$request->get("content");
$id=$request->get("id");
// var_dump($content);
// var_dump($id);
$connection = Yii::$app->db;
$sql = "UPDATE news SET content="$content" WHERE id=".$id;
// $sql="UPDATE news SET content=$content WHERE id=".$id";
// var_dump($sql);die;
$command = $connection->createCommand($sql);
$res=$command->execute();
if ($res) {
echo 1;
}
}
- 上一篇: yii框架搜索后分页查询方法
- 下一篇:没有了