![](/img/trans.png)
[英]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.