Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有服务器端Url.Content的JavaScript语法 currentObject=someValue; var src='';_Javascript_Asp.net_.net - Fatal编程技术网

带有服务器端Url.Content的JavaScript语法 currentObject=someValue; var src='';

带有服务器端Url.Content的JavaScript语法 currentObject=someValue; var src='';,javascript,asp.net,.net,Javascript,Asp.net,.net,但由于Url.Content在中,所以currentObject是“currentObject”,而不是它的值 如何使用currentObject的值而不是名称来编写上述代码?您正在混合使用.NET(我猜是.NET)和javascript currentObject = someValue; var src = '<%=Url.Content("~/Content/images/locations/" + currentObject + ".jpg")%>'; currentObj

但由于Url.Content在中,所以currentObject是“currentObject”,而不是它的值

如何使用currentObject的值而不是名称来编写上述代码?

您正在混合使用.NET(我猜是.NET)和javascript

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

将获取您的src。

尝试将代码更改为:

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