2017-03-17 36 views
0

當試圖在我的字符串中取代%時,出現錯誤「未捕獲的錯誤:語法錯誤,無法識別的表達式:7%with .replace」我錯過了什麼?或者有沒有更好的方法來做到這一點?未捕獲的錯誤:語法錯誤,無法識別的表達式:7%,替換爲

//prints 7% 
var percent = $("#sgE-123456-1-123-element :checked").attr("title"); 

// I'd like to remove the % so I can use the value to multiply 
var percent_removed = $(percent).text().replace('%',''); 

//prints error 
console.log(percent_removed); 

在此先感謝! (:ᘌꇤ⁐ꃳ三

回答

0

我的猜測是簡單地使用切片刪除最後一個字符()

這會看到這樣的:

var percent_removed = percent.slice(0,-1); 
相關問題