未终止的字符串常量 [英] unterminated string constant

查看:174
本文介绍了未终止的字符串常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我遇到了一个JavaScript错误,无法修复未终止的字符串常量.
这就是我想要做的

Hi,
I have this javascript error that I am unable to fix unterminated string constant.
Here is what I am trying to do

var test = '<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas</p>
        <p>ahdndsa</p>';
        document.getElementById('education').innerHTML = test;


推荐答案

如我所见,您尝试使用多行字符串文字.看起来似乎并不那么简单.
在这里查看: http://www.componentart .com/community/blogs/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx [ http://forums.whirlpool.net.au/archive/487804 [ ^ ]
As I see, you try to use multiline string literal. That''s not so straightforward, as it seems.
Look here: http://www.componentart.com/community/blogs/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx[^]
This is also an alternative: http://forums.whirlpool.net.au/archive/487804[^]


字符串常量缺少右引号.字符串常量必须用一对引号引起来.
请参阅: MSDN:JS1015:未终止的字符串常量 [ ^ ]

试试:
A string constant is missing a closing quotation mark. String constants must be enclosed within a pair of quotation marks.
Refer: MSDN: JS1015: Unterminated string constant[^]

Try:
var test = "<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas" + "\n" +
         "<p>ahdndsa</p>"
         document.getElementById('education').innerHTML = test;


我将您的代码复制并粘贴到了text.aspx文件语法中,如下所示,当我修改整个语句时,它工作得很好
Hi I copied and pasted your code in my text.aspx file syntax is given below, and it worked fine when I wright the whole statment
var test = '<p>rajnas asdjhsadnmdas dasjads bnas</p><p>ahdndsa</p>'; 


在一行中,但是如果我在行下写


in a single line, but if i write below line

<p>ahdndsa</p>'; 


在新行中,则仅给出连续的字符串常量错误.

因此,请尝试将(var test)值放在一行中,如下面的代码所示.希望它能做到.



in new line then only its giving unterminated string constant error .

so try to put (var test) value in a single line as in below code . Hope it will do.


<script>
   function aa()
   {
var test = '<p>rajnas asdjhsadnmdas dasjads bnas</p><p>ahdndsa</p>';
         document.getElementById('education').innerHTML = test;

         }
   </script>









<body>
<a href="#" onclick="aa()">click</a>
    <div id="education">
    </div>
</body>



添加了代码块[/编辑]



Code block added[/Edit]


这篇关于未终止的字符串常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆