简体   繁体   中英

JavaScript syntax with server-side Url.Content

currentObject = someValue;
var src = '<%=Url.Content("~/Content/images/locations/" + currentObject + ".jpg")%>';

But since Url.Content is in ', the currentObject is 'currentObject', and not its value.

How to write the above code with currentObject's value, not name?

you are mixing .NET(Im guessing its .NET) and javascript.

currentObject = someValue;
var src = '<%=Url.Content("~/Content/images/locations/")%>' + currentObject + '.jpg';

will get your src.

Try change your code to:

currentObject = someValue;
var src = <%=Url.Content("~/Content/images/locations/")%> + currentObject + ".jpg";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM