layui使用弹窗单值修改


<html>

<head>
    <title>title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layui/css/layui.css">
    <script type="text/javascript" src="__STATIC__/layui/layui.js">script>
head>

<body>
    <div class="price" data-goodsid='12' data-itemid='3' data-oldvalue='3'>123div>
    <script>
    layui.use(['layer', 'form', 'jquery'], function() {
        layui.$(document).on('click', '.price', function() {
            var goods_id = layui.$(this).data('goodsid');
            var item_id = layui.$(this).data('itemid');
            var old_value = layui.$(this).data('oldvalue');
            var _this = layui.$(this);
            layui.layer.prompt({
                title: '请输入需要修改的值',
                value: old_value,
                id: 'new_value',
            }, function(value) {
                layui.$.ajax({
                    url: '/path/to/file',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        action: 'change_price',
                        goods_id: goods_id,
                        item_id: item_id,
                        value: value,
                    },
                    complete: function(xhr, textStatus) {
                        //called when complete
                    },
                    success: function(data, textStatus, xhr) {
                        layui.layer.closeAll();
                        layui.layer.msg(data.msg);
                    },
                    error: function(xhr, textStatus, errorThrown) {
                        layui.layer.msg('网络错误!');
                    }
                });

            })
        });
    });
    script>
body>

html>

你可能感兴趣的:(layui)