【问题标题】:Add a div with text & link button using jQuery使用 jQuery 添加带有文本和链接按钮的 div
【发布时间】:2012-11-13 13:49:54
【问题描述】:

我想使用 jQuery 在 Div 中添加一些文本和一个 asp: 按钮。

代码:

Hi,  <p> Are you sure you want to go ahead</p><p>Please ignore this warning if this is not the first time you are logging in</p>
<asp:button ID="btnProceed" runat="server" Text="Proceed"></asp:button>

实施:

jQ('#proceedDiv').append("<div> Hi,  <p> Are you sure you want to go ahead</p><p>Please ignore this warning if this is not the first time you are logging in</p> <asp:button ID="btnProceed" runat="server" Text="Proceed"></asp:button></div>");

但我收到一条错误消息,提示为 '('

该错误是按钮代码开始的地方。 单独使用文本(而不是按钮控件),代码可以正常工作。有人可以帮我解决吗?

【问题讨论】:

  • 尝试在 append-> \" 中转义双撇号
  • 你的意思是这样的:
  • 尝试将它们改为单引号:&lt;asp:button ID='btnProceed' runat='server' Text='Proceed'&gt;
  • 您似乎混淆了服务器端和客户端技术。 &lt;asp:button&gt; 是一个服务器端组件,它呈现为页面中的 HTML 标记。 jQuery 允许您修改该标记。从客户端添加 &lt;asp:button&gt; 元素不会有任何效果,您应该添加组件生成的实际标记。
  • 那么如何使用 jQuery 添加按钮?

标签: jquery html dynamic add


【解决方案1】:

您需要转义引号...

<asp:button ID="btnProceed" runat="server" Text="Proceed">

需要成为

<asp:button ID=\"btnProceed\" runat=\"server\" Text=\"Proceed\">

还要注意

<button onclick="doSomething()">Click Me</button>

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多