如何在append()中破坏html?

发布于 2024-11-17 18:36:28 字数 535 浏览 1 评论 0原文

我可以使用任何技巧来破坏 append() 中的 html 吗?

例如,像这样的事情就太棒了!

// Append a popup for displaying the security checking form.
$(document.body).append("
<div id='popup-result' class='popup-outer'>
<div class='popup-inner'>
    <div class='close'><a href='#' class='button-close'>x close</a></div>
    <div class='respond-message'></div>
    <div class='form-confirm'></div>
</div>
</div>");

这样我就不必在一行中编写 html - 很难阅读和调试!

Any trick I can use to break the html in append()?

For instance, something like this would be great!

// Append a popup for displaying the security checking form.
$(document.body).append("
<div id='popup-result' class='popup-outer'>
<div class='popup-inner'>
    <div class='close'><a href='#' class='button-close'>x close</a></div>
    <div class='respond-message'></div>
    <div class='form-confirm'></div>
</div>
</div>");

so that I don't have to do the html in one line - it's difficult to read and debug!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是年少的欢喜 2024-11-24 18:36:28

你有两个选择。您可以使用新行文字语法:

// Append a popup for displaying the security checking form.
$(document.body).append("\
<div id='popup-result' class='popup-outer'>\
<div class='popup-inner'>\
    <div class='close'><a href='#' class='button-close'>x close</a></div>\
    <div class='respond-message'></div>\
    <div class='form-confirm'></div>\
</div>\
</div>");

这可行,但可能会混淆一些 IDE(我上次尝试时 Visual Studio 就是这样做的。或者,如果您实际上不需要新行,您可以将每一行设为自己的字符串并连接字符串) :

// Append a popup for displaying the security checking form.
$(document.body).append(
"<div id='popup-result' class='popup-outer'>" +
"<div class='popup-inner'>" +
    "<div class='close'><a href='#' class='button-close'>x close</a></div>" +
    "<div class='respond-message'></div>" +
    "<div class='form-confirm'></div>" +
"</div>" +
"</div>");

You have two options. You can use the new line literal syntax:

// Append a popup for displaying the security checking form.
$(document.body).append("\
<div id='popup-result' class='popup-outer'>\
<div class='popup-inner'>\
    <div class='close'><a href='#' class='button-close'>x close</a></div>\
    <div class='respond-message'></div>\
    <div class='form-confirm'></div>\
</div>\
</div>");

This works, but may confuse some IDEs (Visual Studio does that last time I tried it. Or you can make each line it's own string and concatenate the strings if you don't actually want new lines:

// Append a popup for displaying the security checking form.
$(document.body).append(
"<div id='popup-result' class='popup-outer'>" +
"<div class='popup-inner'>" +
    "<div class='close'><a href='#' class='button-close'>x close</a></div>" +
    "<div class='respond-message'></div>" +
    "<div class='form-confirm'></div>" +
"</div>" +
"</div>");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文