i have a url like this. http://localhost:8080/steer/trip/create/3. where in my page i want to get value "3" using the jquery . please help me
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- Correctly parse PDF paragraphs with Python
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
Plain js
The value that you require is in
val
It may be overkill here, but for URL parsing, I found this useful:
In your case, this would boil down to something like:
This will output "3" or basically the whole last segment of the url after the last "/" slash.
Here is a easy to read and understand JS function that you can use to retrieve any variable from url.
All you need to do is call this function with name of the variable that you want to filter and it will return the value back to you.
Hope it helps:
From: Highlight a button based on location
I am assuming you want to access the parameter value of your controller's action method via jQuery in the client.
In such case, I would rather emit the parameter value as a metadata in a view and query it with jQuery instead of parsing the url itself (you need to decide where to emit, though).
In ASP.NET MVC, if you have a Route that accepts the following pattern: {controller}{action}{param}, http:\myhost\mycontroller\myaction\3 and http:\myhost\mycontroller\myaction?param=3 are equivalent and parsing only one URL pattern will not be sufficient.
You may find examples in jQuery mdatadata plugin useful.
The following is one of the examples in the link above.
Please disregard this answer if my assumption is not correct.