[英]What is the easiest way to read/manipulate query string params using javascript?
[英]What is the easiest way to pick portions of a string based on a template in javascript
我正在尝试从此字符串中获取值:
-webkit-gradient(linear, right top, left top, color-stop(0, #FF7417), color-stop(1, #82A8FF))
并将其转换为其他格式(-moz,-o-,-webkit-linear等)。 目前,我正在通过拆分字符串(使用'(',','等)然后将片段重新排列为新格式来做到这一点,有没有简单的方法呢?
注意:我不需要在各种渐变格式之间进行转换的方法。 我只需要一种通用方法即可根据预定义的模板来选择字符串的必需部分。
您应该使用正则表达式捕获每个集合,例如/color-stop\\(0,.+?\\)/
应该让您获得第一个颜色停止部分。 然后,您只需为每个结果创建一个新字符串:
"-webkit-gradient" + color + linear + righttop + etc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.