js中的encodeURIComponent()函数

encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。

$scope.linktotheme = function () {
if ($scope.curthemeid == null) return;
$("#settings").modal('hide');
var tempurl = "";
var strceshi = $("#images").attr("imagelist").replace("iopcmd=convert&dst=jpg&Q=70|", "");
var imagesstr = strceshi.replace("iopcmd=convert&dst=jpg&Q=70|", "");
var imagesstr1 = imagesstr.replace("iopcmd=convert&dst=jpg&Q=70|", "");
var imagesstr2 = imagesstr1.replace("iopcmd=convert&dst=jpg&Q=70|", "");
var imagesstr3 = imagesstr2.replace("|iopcmd=convert&dst=jpg&Q=70", "");
switch (typesign) {
case 0:
tempurl = "/hoteltheme/theme" + $scope.curthemeid + "?bgcolor=" + $scope.curcolor.substring(1, 7) + "&themeid=" + $scope.curthemeid;
break;
case 1:
tempurl = "/hoteltheme/theme" + $scope.curthemeid + "?themeid=" + $scope.curthemeid;
break;
case 2:
tempurl = "/hoteltheme/theme" + $scope.curthemeid + "?bgimgs=" + encodeURIComponent(imagesstr3) + "&themeid=" + $scope.curthemeid;
break;
case 3:
tempurl = "/hoteltheme/theme" + $scope.curthemeid + "?themeid=" + $scope.curthemeid;
break;
}
$location.url(tempurl);
};

请注意 encodeURIComponent() 函数 与 encodeURI() 函数的区别之处,前者假定它的参数是 URI 的一部分(比如协议、主机名、路径或查询字符串)。因此 encodeURIComponent() 函数将转义用于分隔 URI 各个部分的标点符号。

原文地址:https://www.cnblogs.com/zhangxiaolei521/p/5231559.html