单击文本之后变输入框做ajax保存加强版

源码技巧9年前 (2016-11-29)14740

html页面代码如下:
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<span class="price" style="display: inline;">20.00</span>
    <span class="textInput" style="display: none;">
        <input type="hidden" name="id" value="1">
        <input name="price" type="text" value="20.00">
        <span class="postPrice">aaaa</span>
</span>
<script>
$(function(){
    $(".price").click(function(){
        $(this).hide();
        $(this).next().fadeIn('slow');
    })
    $(".postPrice").click(function(){
        var thisPrice = $(this);
        var price = thisPrice.parent().find('input[name="price"]').val();
        var id = thisPrice.parent().find('input[name="id"]').val();
        var url = 'http://www.xxx.com/index.php?s=Plus-Stars-ajaxSave';
        $.post(url,{price:price,id:id},function(data){
            if(data){
                thisPrice.parent().hide();
                thisPrice.parent().prev().html(price).fadeIn();
            }else{
                thisPrice.parent().html('保存失败');
            }
        })
    })
})
</script>

php异步接收更改数据库页面程序save.php:
public function ajaxSave(){
    $data['price'] = intval($_POST['price']);
    echo $data['price'];
    
    //$res = M('course')->where('id = '.intval($_POST['id']))->save($data);
    echo $res;
}

“单击文本之后变输入框做ajax保存加强版” 的相关文章

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。