为什么有些网站(或提供客户端javascript代码的广告客户)采用了在通话中拆分<script>和/或</script>标记的技术document.write()?
我注意到亚马逊也这样做了,例如:
<script type='text/javascript'>
if (typeof window['jQuery'] == 'undefined') document.write('<scr'+'ipt type="text/javascript" src="http://z-ecx.images-amazon.com/images/G/01/javascripts/lib/jquery/jquery-1.2.6.pack._V265113567_.js"></sc'+'ript>');
</script>
Run Code Online (Sandbox Code Playgroud) 我在我的MVC3项目中使用Razor.而且我也在使用FullCalendar JQuery插件.因此,当我试图填充数组时,它运行良好.除了一件事.如果s.Name包含撇号,它就会像'我想要的那样渲染.我尝试使用不同的方法,如Encode和Decode,甚至MvcHtmlString.Create,结果总是一样的.
这是代码片段:
<head>
<script type='text/javascript'>
$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
month: 5,
year: 2011,
editable: false,
events: [
@foreach (var s in ViewBag.Sessions)
{
@:{
@: title: '@s.Name',
@: start: new Date(@s.Starts.Year, @s.Starts.Month-1, @s.Starts.Day),
@: end: new Date(@s.Ends.Year, @s.Ends.Month-1, @s.Ends.Day)
@:},
}
]
});
});
</script>
Run Code Online (Sandbox Code Playgroud)