容器标签可以放在HEAD中吗?
在文档的 标记部分中,我有代码可以让我使用 JavaScript 中的 asp.net 控件的 Id,如下所示:
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
但是,如果我想修改页面结构在页面生命周期的后期阶段,它会给我一个错误,因为我在那里有 ASP 标签。解决方法是将 ASP 标记包含在服务器控件中,如下所示:
<div id="customerIdContainer" runat="server">
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
</div>
但随后我收到一条警告,指出 head 标记中不允许使用 div 标记。那么是否有一个在头部有效的容器标签,我可以添加 runat="server" 以使其成为服务器控件,以便我可以在没有警告的情况下解决此问题?
In a section in the <head>
tags of my document I have code that lets me use the Id of my asp.net control from JavaScript like this:
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
However, if I want to modify the page structure in later stages of the page life cycle, it give me an error because I have the ASP tags in there. A work-around is enclosing the ASP tags in a server control like this:
<div id="customerIdContainer" runat="server">
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
</div>
But then I get a warning that a div tag is not allowed in the head tag. So is there a container tag that is valid in the head that I can add runat="server" to to make it a server control so I can workaround this problem without the warnings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些想法:
Some thoughts:
将 script 标签移到 head 部分之外。 ;-)
Move the script tag outside the head section. ;-)