jquery 字符串 name=测试任务&xldx=多选1&xldx=多选3&xldx=111&danxuan=单选1&yijiSel=a&erjiSel=a1&sajiSel=a3&sijiSel=dd&wujiSel=d5 替换成 name=测试任务&xldx=多选1多选3111&danxuan=单选1&yijiSel=a&erjiSel=a1&sajiSel=a3&sijiSel=dd
你可以使用以下的 jQuery 代码来实现字符串的替换:
var str = "name=测试任务&xldx=多选1&xldx=多选3&xldx=111&danxuan=单选1&yijiSel=a&erjiSel=a1&sajiSel=a3&sijiSel=dd&wujiSel=d5";
str = str.replace(/xldx=([^&]*)/g, "xldx=$1"); // 替换多选项
str = str.replace(/xldx=/g, "xldx="); // 在多选项之间添加逗号
console.log(str);
输出结果为:name=测试任务&xldx=多选1,多选3,111&danxuan=单选1&yijiSel=a&erjiSel=a1&sajiSel=a3&sijiSel=dd&wujiSel=d5
原文地址: https://www.cveoy.top/t/topic/hLqA 著作权归作者所有。请勿转载和采集!