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

字符串中有javascript代码的问题
我知道</script>在JS字符串中要转义,但是今天写了一段JS代码,函数中用javascript输出一段HTML
JScript code

    var newHTML = "<p><a href=\"#\" onClick=\"javascript:return showRecord(1,100);\">首页</a>  <a href=\"#\" onClick=\"javascript:return showRecord("+(currentPageNo-1)>0?(currentPageNo-1):1+",100);\">上一页</a> | <a href=\"#\" onClick=\"javascript:return showRecord("+(currentPageNo+1)>((totalRecords+pageSize-1)/pageSize)?currentPageNo:((totalRecords+pageSize-1)/pageSize)+",100);\">下一页</a> <a href=\"#\" onClick=\"javascript:return showRecord("+((totalRecords+pageSize-1)/pageSize)+",100);\">最后一页</a> </p>";



结果不能正常输出,输出类似于
HTML code

3.24,100);">下一页 最后一页


看样子似乎javascript:return showRecord执行了么?如果在JS里输出含有javascript:return有什么讲究嘛
帮忙谢谢啦

------解决方案--------------------
HTML code

var newHTML = "<p><a href=\"#\" onClick=\"javascript:return showRecord(1,100);\">首页</a>  <a href=\"#\" onClick=\"javascript:return showRecord("+((currentPageNo-1)>0?(currentPageNo-1):1)+",100);\">上一页</a> | <a href=\"#\" onClick=\"javascript:return showRecord("+((currentPageNo+1)>((totalRecords+pageSize-1)/pageSize)?currentPageNo:((totalRecords+pageSize-1)/pageSize))+",100);\">下一页</a> <a href=\"#\" onClick=\"javascript:return showRecord("+((totalRecords+pageSize-1)/pageSize)+",100);\">最后一页</a> </p>";