1

我在空白页上有这个 javascript:

Please show this number to your supplier:
<script>
document.write(document.URL);
</script>

所以它显示

"Please show this number to your supplier: http://www.exaple.com/invoices/123456789"

如何仅从 url 中提取数字以便我得到这个?

"Please show this number to your supplier: 123456789"
4

4 回答 4

1
if (location.search != "")
{
var x = location.search.substr(1).replace(/%2520/g,' ').split(";")
for (var i=0; i<x.length; i++)
{
    var y = x[i].split("=");
    document.write(y[0])
}
}   
于 2015-05-26T08:48:25.040 回答
0
document.URL.substring(document.URL.lastIndexOf('/'), document.URL.length);
于 2013-07-18T10:20:41.030 回答
0
v = 'http://www.exaple.com/invoices/123456789';
number = v.replace(/[^0-9]/g,"");

console.log( number); //123456789
于 2013-07-18T10:23:10.253 回答
0
var patt=/(\d+)$/;
var url=document.URL;
var num=0;
if (url.match(patt)) {
  var num_str=url.match(patt)[1];
  num=parseInt(num_str, 10);
}

$= 字符串结束。

正则表达式

于 2013-07-18T10:27:45.720 回答