我有以下類型的網址:localhost/Support/My-DNN-Module-Name/ID/133我需要始終在最后提取ID值,在本例中為133。這就是我目前正在做的提取它:if (url) { // try tograb number as int from url var intValue = url.match( /\d+/ ); if (intValue) { console.log("converted url to int value and the result is: " + intValue); } else { console.log("could not convert url to int value"); }}顯然,如果URL包含其他數字,例如在本地主機作為實際IP地址輸入的情況下,這不是很好。我怎么能只定位ID之后的最后一個部分,并抓住任何可能存在的數字,理想情況下,與之前的URL可能是什么樣子無關?
Javascript 如何從 URL 中提取 ID 作為 INT?
ABOUTYOU
2022-08-04 09:36:04