问题
So let's say there's a URL http://example.com/index.html/hello/hi where "hello" and "hi" are parameters.
How would you use javascript and forms method POST to extract the parameters?
回答1:
Your subject is a little bit vague. However, I thought I'd made an example of possibilities. http://jsfiddle.net/tive/LjbPq/
The idea is to split the URL for each character /, in whatever way you received it.
var parts = document.URL.split("/");
Since split() returns an array (zero based), you need to distract 1 from the total length to get the last index.
var lastPart = parts[parts.length - 1];
Run this in a for loop, and you should get the idea as occurring in the example.
- documentation on document.URL to retreive the complete URL
- documentation on window.location to use properties of a url (protocol, href, pathname, ...)
回答2:
this could work...
var secondvar = window.location.href.split('/')[window.location.href.split('/').length];
var firstvar = window.location.href.split('/')[window.location.href.split('/').length-1];
来源:https://stackoverflow.com/questions/11767140/using-forms-and-post-method-to-get-url-parameters-through-javascript