Change the value of a variable after it's been set
here's my problem.
I have this piece of code that sets the user location as coordinates in a textbox.
var initialLocation;
$('#from').val(initialLocation);
The initialLocation variable gets the user current location as coordinates and then $('#from').val(initialLocation);
puts those coordinates in the textbox "from".
But instead of boring coordinates like "45.542307开发者_如何学Python, -73.567200" I'd like my textbox to simply show "Your location".
So basically, I want to have the coordinates in my textbox, but change what the user sees from "45.542307, -73.567200" to "Your location".
Is it possible to do such a thing ?
Thanks !
You can use data method of Jquery which stores data specific to the element
$("#from").data("currentLocation", initialLocation).val("Your location");
//To retrieve the currentLocation
$("#from").data("currentLocation");
Just have 2 text boxes, one that is hidden and has the real value and another which is visible which you put "Current Location" into.
精彩评论