日期:2014-05-16  浏览次数:20346 次

JS提示“ 未结束的字符串常量”
<script type="text/javascript"> 
//<![CDATA[
(function NTES_Nav(){
function $_G(id){
return document.getElementById(id);
}
function clickselect(e){
e = e || window.event;
e.cancelBubble = true;
var name = this.innerHTML;
var txt = document.createTextNode(name);
selected.removeChild(selected.firstChild);
selected.appendChild(txt);
select_main.style.display = "none";
var title = this.getAttribute("title");
$_G("siteName").value = title;
}
function a_mouseover () {
this.className = "active";
}
function a_mouseout () {
this.className = "";
}
$_G("divSelect").innerHTML = '<input id="siteName" type="hidden" value="系统网 
 图吧频道" name="site" /><div id="select_area" class="select_box"><span id="selected" class="search_site">标题</span><div id="select_main" class="select_list"><a title="标题">标题</a><a title="">简介</a><a title="">内容</a><a title="">作者</a></div></div>';
var select_area = $_G("select_area"), selected = $_G("selected"), select_main = $_G("select_main"), select_list = select_main.getElementsByTagName("a"), len = select_list.length;
select_area.onclick = select_main.onmouseover = function(){
select_main.style.display = "block";
}
select_main.onmouseout = function(){
select_main.style.display = "none";
}

for (var i = 0; i < len; i++) {
select_list[i].onclick = clickselect;
select_list[i].onmouseover = a_mouseover;
select_list[i].onmouseout = a_mouseout;
}
})();
//]]>
</script>

错误提示为红色部分提示, 未结束的字符串常量,新手学习JS,测试加 /,/N,总是提示错误信息

------解决方案--------------------
this.className = "";
}

这里}去掉




)();

前面加个}
------解决方案--------------------
$_G("divSelect").innerHTML = '<input id="siteName" type="hidden" value="系统网 
 图吧频道

是你这里换行了,把换行去掉,把这个字符串写成一行就行了,
JScript code
$_G("divSelect").innerHTML = '<input id="siteName" type="hidden" value="系统网图吧频道" name="site" /><div id="select_area" class="select_box"><span id="selected" class="search_site">标题</span><div id="select_main" class="select_list"><a title="标题">标题</a><a title="">简介</a><a title="">内容</a><a title="">作者</a></div></div>';