douyan8772 2016-06-22 09:31
浏览 83

如何在javascript中获取$ this数组中的值

In message variable I am getting the multiple selected, how to store them in array, after this store in database?

<script type="text/javascript">
    $(function () {
        $('#lstFruits').multiselect({
            includeSelectAllOption: true
        });
        $('#btnSelected').click(function () {
            var selected = $("#lstFruits option:selected");
            // document.write(selected);

            //.var array = string.split(",").val(selected);

            var message = "";
            selected.each(function () {
                message += $(this).val();
                // here I am getting the selected ids like 2,4,5 and I
                // want to submit all ids in the database. 
                // While, when I am submitting currently only the last 
                // id is being submitted.
                var vale = [$(this).val()];
                //document.write(vale);
                $('#second').val(vale);
            });
            alert(message);
        });
    });

</script>

How to store all selected values in array and then submit in php page by query?

  • 写回答

3条回答 默认 最新

  • dongnuo3749 2016-06-22 09:39
    关注

    Try to save the values in array & name of the field whose id is second should be like second[]

    <script type="text/javascript">
        $(function () {
            $('#lstFruits').multiselect({
                includeSelectAllOption: true
            });
            $('#btnSelected').click(function () {
                var selected = $("#lstFruits option:selected");
                var message = [];
                selected.each(function () {
                    message.push($(this).val());
                });
                $('#second').val(message);
                alert(message);
            });
        });
    
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大