勾选复选框,把所获取到的id以json格式通过ajax传送出去,该怎么做? 15

<divid="id_none_1"><spanid="id_step-7-tn"class="must-input"style="*top:2px;"></span><... <div id="id_none_1">
<span id="id_step-7-tn" class="must-input" style="*top: 2px;"></span>
<span class="title">自定义任务步骤:</span><br><br>
<div style="border: 1px;">
必选项:
<input id="step_option1" class="" type="checkbox" name="sortmsg1" onclick="sortmsgchange(this)" value="0" checked="" disabled="disabled"> 搜索结果
<input id="step_option2" class="" type="checkbox" name="sortmsg1" onclick="sortmsgchange(this)" value="0" checked="" disabled="disabled"> 目标商品头部
<input id="step_option3" class="" type="checkbox" name="sortmsg1" onclick="sortmsgchange(this)" value="2" checked="" disabled="disabled"> 附加商品1头部
<input id="step_option4" class="" type="checkbox" name="sortmsg1" onclick="sortmsgchange(this)" value="3" checked="" disabled="disabled"> 附加商品2头部
<input class="" type="checkbox" name="sortmsg1" name="sortmsg1" onclick="sortmsgchange(this)" value="0" checked="" disabled="disabled">目标商品尾部
<input class="" type="checkbox" name="sortmsg1" name="sortmsg1" onclick="sortmsgchange(this)" value="2" checked="" disabled="disabled">附加商品1尾部
<input class="" type="checkbox" name="sortmsg1" name="sortmsg1" onclick="sortmsgchange(this)" value="3" checked="" disabled="disabled">附加商品2尾部<br><br>
<input style="margin-left:56px;" class="" type="checkbox" name="sortmsg1" onclick="sortmsgchange(this)" value="1" checked="" disabled="disabled"> 下单支付
<input class="" type="checkbox" name="sortmsg1" onclick="sortmsgchange(this)" value="0" checked="" disabled="disabled"> 物流截图<br><br>

可选项:
<input id="step_option5" class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1"> 货比三家1
<input id="step_option6" class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1"> 货比三家2
<input id="step_option7" class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1"> 店铺浏览1
<input id="step_option8" class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1"> 店铺浏览
<input class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1" > 浏览评价
<input class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1" > 聊天
<input class="" type="checkbox" name="sortmsg2" onclick="sortmsgchange(this)" value="1" > 评价
<input type="button" value="提交">

</div>
</div>
{"step_1":["目标商品"]}要转换成这个形式的json
展开
 我来答
miniappdltshxxyvklg7
2017-02-25 · 超过89用户采纳过TA的回答
知道小有建树答主
回答量:325
采纳率:0%
帮助的人:124万
展开全部

我默认你已经引入了jquery库

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<前端js代码

;function sortmsgchange(obj){
    //判断复选框是否选中
    var that = $obj,
        id = that.attr('id');
        if(that.is('checked') == true){
            //此时为选中
            $.ajax({
                type : 'post',
                url : 'test',
                data : {
                    id : id
                },
                success:function(response){
                    //服务端返回的信息
                    alert(response);
                }
            });
        }else{
           //此时无操作,从选中状态更换到非选中状态      
                
        };

};



<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<服务端test方法

function test(){
    //这个就是你获得的id,如果是json可能需要json转换成字符串,你自己想办法去转换
    echo $_POST['id'];
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式