What should be the correct javascript syntax in this case?
I have a code that is a mix of HTML and js. I cannot get it correct.
location.description开发者_JS百科 + '<br><a href="javascript:void(0);" onclick="showStreet;">ShowStreet </a><br>'+ location.lat + '<br> + location.lng
Can anyone help me with it?
You have two problems in that:
- You were missing
'
afterlocation.lat + '<br>
- You were not suffixing the function
showStreet
with()
Try this:
location.description + '<br><a href="javascript:void(0);" onclick="showStreet();">ShowStreet </a><br>'+ location.lat + '<br>' + location.lng
Note: You might want to add the return
keyword for your function depending on whether you want to cancel it at some point.
Did you mean onclick="showStreet()"
(instead of onclick="showStreet;"
)?
From your question, it's unclear what the problem is.
location.description + '<br><a href="javascript:void(0);" onclick="showStreet();">ShowStreet </a><br>'+ location.lat + '<br>' + location.lng
You have to call a function inside onclick and there you were missing parenthesis. And also a single quote after the last <br>
精彩评论