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