首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未终止字符串的javascript错误

问未终止字符串的javascript错误
EN

Stack Overflow用户
提问于 2010-05-28 12:36:59
回答 5查看 874关注 0票数 2

我想传递一个javascript函数的参数,它是一个字符串。这个javascript函数是鼠标悬停的一个提示框。

我使用的字符串是这样的:

边缘整理:横幅的每一面/边缘(1/2“到2")都是折叠和胶粘的(特殊乙烯基溶液)或热压。这是最常见和最好的完成选项。 缝制完成:横幅的每一面/边(1“到2")都折叠在背面,用白线缝制/缝制。这不是一个常见的选项,因为可以在横幅上看到线程。

现在,在鼠标悬停的后备箱中,必须显示上述给定的文本,因为它与段落断点一起显示在上面。但是当我在函数中作为参数传递上面的参数时,加上一些反斜杠以识别一些标点符号,直到给出未终止字符串的javascript错误.

我是这样做的:

代码语言:javascript
复制
onMouseover="showhint('Hemmed Finish\: Every side/edge \(1/2\'\' to 2\'\'\) of the banner are folded and glued \(special vinyl solution\) or heat pressed. This is the most common and best finish option.Stitched Finish\: Every side/edge \(1\'\' to 2\'\'\) of the banner are folded in the back and stitched/sewed with white thread. This is not a common option as thread can be seen on the banner', this, event, '250px')"

请你帮我纠正这个问题.

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-05-28 12:49:14

好吧,我有个解决办法:

代码语言:javascript
复制
<element onMouseover="showhint('&lt;p&gt;Hemmed Finish: Every side/edge (1/2&quot; to 2&quot;) of the banner is folded and glued (special vinyl solution) or heat pressed. This is the most common and best finish option.&lt;/p&gt;&lt;p&gt;Stitched Finish: Every side/edge (1&quot; to 2&quot;) of the banner is folded in the back and stitched/sewed with white thread. This is not a common option as thread can be seen on the banner&lt;/p&gt;', this, event, '250px')" />

您必须使用&quot;转义XML风格的引号。

参见一个工作示例这里。

票数 4
EN

Stack Overflow用户

发布于 2010-05-28 12:42:13

检查一下这个:

代码语言:javascript
复制
onMouseover="showhint('Hemmed Finish: Every side/edge (1/2\'\' to 2\'\') of the banner are folded and glued (special vinyl solution) or heat pressed. This is the most common and best finish option.Stitched Finish: Every side/edge (1\'\' to 2\'\') of the banner are folded in the back and stitched/sewed with white thread. This is not a common option as thread can be seen on the banner', this, event, '250px')"

您不需要转义:括号如下(

代码语言:javascript
复制
<script type="text/javascript">
<!--//
function alert2()
{
alert ("Don't forget the curly "+
"brackets - \nThey are essential!");
}
//-->
</script>
票数 1
EN

Stack Overflow用户

发布于 2010-05-28 12:47:35

我在这里看到了两个潜在的问题。

  1. JavaScript和许多其他编程语言一样,使用“字符来标记字符串的开始和结束。您的提示框文本包含一个",所以当JavaScript遇到它时,它会认为您的字符串已经结束。要解决这个问题,您应该将每个“在字符串中”引用为“\”。这告诉JavaScript,您不打算结束字符串,而是计划在字符串中放置一个“。
  2. 类似地,JavaScript不允许将“段落中断”直接放置在字符串中。相反,每次需要在字符串中返回回车时,都必须键入\n。

因此,您应该如何定义hintbox字符串:

代码语言:javascript
复制
hintbox = "Hemmed Finish: Every side/edge (1/2\" to 2\") of the banner are folded and glued (special vinyl solution) or heat pressed. This is the most common and best finish option.\n\nStitched Finish: Every side/edge (1\" to 2\") of the banner are folded in the back and stitched/sewed with white thread. This is not a common option as thread can be seen on the banner.";

这通常被称为“转义字符串”,一个快速的Google应该会给你更多的关于上面图片的信息。

编程愉快!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2928979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档