代码格式测试
2017-07-22 本文已影响0人
riyihu
<div class="layui-form-item">
<label for="unit_price" class="layui-form-label">
<span class="x-red">*</span>购买单价
</label>
<div class="layui-input-inline">
<select id="unit_price" name="unit_price">
<option value="" selected="">请选择</option>
<option value="1">1元</option>
<option value="10">10元</option>
<option value="100">100元</option>
</select>
</div>
</div>
<!-- 总需人次 = 商品价格/购买单价 -->
<div class="layui-form-item">
<label for="max_buy" class="layui-form-label">
<span class="x-red">*</span>总需人次
</label>
<div class="layui-input-inline">
<input type="text" id="max_buy" name="max_buy"
autocomplete="off" class="layui-input" disabled>
</div>
</div>
<!-- <div class="layui-form-item">
<label for="user_max_buy" class="layui-form-label">
限购单数
</label>
<div class="layui-input-inline">
<input type="text" id="user_max_buy" name="user_max_buy"
autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">
默认为0,不限购
</div>
</div> -->
<div class="layui-form-item">
<button class="layui-btn layui-btn-small" lay-filter="add" lay-submit="">
确认添加
</button>
</div>
</form>
<script src="/js/x-layui.js" charset="utf-8"></script>
<script>
layui.use(['form','layer'], function(){
$ = layui.jquery;
var form = layui.form();
//监听提交
form.on('submit(add)', getSubmitForm('{:url("admin/activity/save")}', {}));
//计算总人次
$('#unit_price').change(function (){
var unit_num = $(this).val();
var gprice = $('#good_marketprice').val();
console.log(unit_num, gprice);
$('#max_buy').val(Math.ceil(gprice/unit_num));
});
});
function setGoods(good_id, goods_name,good_marketprice) {
$('#good_id').val(good_id);
$('#goods_name').val(goods_name);
$('#good_marketprice').val(good_marketprice);
}
</script>