How can I format this string in jquery so that it will include the value of the title variable?
I need to find a way to format the string such that I can replace "_TITLE_TO_REPLACE_" with the title. I have tried using single quotes so that the title can be entered in that spot, but I don't know how to escape the quotes around FavoriteWallpaper and Wallpaper, such that the URL.Action call is valid.
var title = $(this).parent().siblings(".imageLink").children().attr('title');
$(this).attr('href', function() {开发者_Python百科
var url = '<%: Url.Action("FavoriteWallpaper", "Wallpaper", new { wallpaperId= "_TITLE_TO_REPLACE_"}) %>';
return url;
});
Im assuming you need to do this after the page renders your url.action.
return url.replace('_TITLE_TO_REPLACE_',title);
Try this:
var url = '<%: Url.Action("FavoriteWallpaper", "Wallpaper", new { wallpaperId= "' + title + '"}) %>';
精彩评论