我在Page Load方法
中调用C#文件中的JavaScript函数<script type="text/javascript">
function googleMaps(aLocations, aTitles, aSummary) {
$(document).ready(function () {
$('#test').GoogleMap(aLocations, aTitles, aSummary, {
type: 3,
zoom: 9
});
});
}
</script>
</script>
和JavaScript代码
function googleMaps(aLocations, aTitles, aSummary) {
$(document).ready(function () {
$('#test').GoogleMap(aLocations, aTitles, aSummary, {
type: 3,
zoom: 9
});
});
}
我收到此错误
caught SyntaxError: Unexpected token function
错误在以下行
WebForm_InitCallback();var _spFormDigestRefreshInterval = 1440000;googleMaps('["keswick,cumbria,uk","grasmere,cumbria,uk","ambleside,cumbria,uk"]','["Keswick","Grasmere","Ambleside"]','["\u003cdiv class=\"ExternalClass1721CEC0617F42C887D068EA11963662\"\u003e\u003cfont class=\"ms-rteThemeForeColor-2-0\" face=\"Consolas\" size=\"2\"\u003e\u003cfont face=\"Consolas\" size=\"2\"\u003e\u003cfont face=\"Consolas\" size=\"2\"\u003e\u003cp\u003e\u0026lt;h3\u0026gt;Keswick\u0026lt;/h3\u0026gt;\u0026lt;p\u0026gt;Keswick is a market town and civil parish within the Borough of Allerdale in Cumbria, England. It had a population of 4,984, according to the 2001 census.\u0026lt;/p\u0026gt;\u003c/p\u003e\u003c/font\u003e\u003c/font\u003e\u003c/font\u003e\u003c/div\u003e","\u003cdiv class=\"ExternalClass4AFD1E67B5374D86A656C26E69EEE124\"\u003e\u003cfont class=\"ms-rteThemeForeColor-2-0\" face=\"Consolas\" size=\"2\"\u003e\u003cfont face=\"Consolas\" size=\"2\"\u003e\u003cfont face=\"Consolas\" size=\"2\"\u003e\u003cp\u003e\u0026lt;h3\u0026gt;Grasmere\u0026lt;/h3\u0026gt;\u0026lt;p\u0026gt;Grasmere is a village, and popular tourist destination, in the centre of the English Lake District. It takes its name from the adjacent lake of Grasmere, and is associated with the Lake Poets.\u0026lt;/p\u0026gt;\u003c/p\u003e\u003c/font\u003e\u003c/font\u003e\u003c/font\u003e\u003c/div\u003e","\u003cdiv class=\"ExternalClass8A0E058969E04AF59AF3B8FDACAB4576\"\u003e\u003cfont class=\"ms-rteThemeForeColor-2-0\" face=\"Consolas\" size=\"2\"\u003e\u003cfont face=\"Consolas\" size=\"2\"\u003e\u003cfont face=\"Consolas\" size=\"2\"\u003e\u003cp\u003e\u0026lt;h3\u0026gt;Ambleside\u0026lt;/h3\u0026gt;\u0026lt;p\u0026gt;Ambleside is a town in Cumbria, in North West England. Historically within the county of Westmorland, it is situated at the head of Windermere, Englands largest lake. The town is within the Lake District National Park.\u0026lt;/p\u0026gt;\u003c/p\u003e\u003c/font\u003e\u003c/font\u003e\u003c/font\u003e\u003c/div\u003e"]')function loadMDN2() { EnsureScript('MDN.js', typeof(loadFilterFn), null); }
答案 0 :(得分:2)
var serializer = new JavaScriptSerializer();
var serializedResult1 = serializer.Serialize(getLocations());
var serializedResult2 = serializer.Serialize(getTitles());
var serializedResult3 = serializer.Serialize(getSummary());
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "googleMaps('" + serializedResult1 + "','" + serializedResult2 + "','" + serializedResult3 + "');", true);
答案 1 :(得分:1)
我将你的JS复制并粘贴到JSLint中并得到了同样的错误,但是当我将函数的开头移动到JSLint中的最顶层时,它就消失了。它表示它希望第1列的功能。似乎表明可能值得将该功能提升到最顶层,并使其成为标签之后的第一件事 - 即移除它前面的空白区域。快进JSLint,你会明白我的意思