javascript - HTML 内容中的 HTML

标签 javascript jquery html

如何将大的 HTML 标签嵌入到这个场景中?

$(document).ready(function () {
            window.showim = function(src) {
                $("#divcont1").html(src);
            };
        });

而不是 <h1>test</h1>我需要插入大的 html 内容

<span class="spcusr" onclick="showim('<h1>test</h1>');">click me</span>

      <div id="divcont1"></div>

我的大型 HTML 内容示例

<div style="width:976px; height:576px; overflow:hidden; background-repeat:no-repeat; background-image:url(MASTER.jpg)">
<table style="cursor:pointer;">
  <tr height="144">
    <td width="485"  onclick="window.location='#';">&nbsp;</td>
    <td width="485" onclick="window.location='#';">&nbsp;</td>
  </tr>
  <tr height="144">
    <td onclick="window.location='#';">&nbsp;</td>
    <td onclick="window.location='#';">&nbsp;</td>
  </tr>
  <tr height="144">
    <td onclick="window.location='#';">&nbsp;</td>
    <td onclick="window.location='#';">&nbsp;</td>
  </tr>
  <tr height="144">
    <td onclick="window.location='#';">&nbsp;</td>
    <td onclick="window.location='#';">&nbsp;</td>
  </tr>
</table>
</div>

我的主要问题是双引号和引号。因为 onclick="showim(' this started with single quotes and no more quotes allowed inside ')";那么,遇到这种情况怎么办?谢谢

最佳答案

你必须转义比 "和 ' 更深的引号。

这里,可能对你有帮助: Escape quotes in JavaScript

关于javascript - HTML 内容中的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21432203/

相关文章:

javascript - 什么是@angular/core/bundles/core.umd.js

JavaScript/CSS/图像引用路径

javascript - 如何根据数组中的一个键值找到其他键的值?

html - 如何在 html 中的电子邮件跨度之间添加空格?

css - 如何使外部事件框动态扩展和空心圆对齐

jquery - CSS 在浏览器中未处于事件状态时未更新?

javascript - 我会用什么表达方式?

java - 无法在 AJAX post 请求中自动绑定(bind)到 Spring MVC 中的 Java 对象

javascript - 叠瓦循环+超时有时会失败

javascript - 在 jquery joomla 中获取具有特定模式的类名的元素