如何使用runat ="server"在asp.Net中的脚本标签上 [英] How can I use runat="server" on a script tag in asp.Net
问题描述
我不一定需要在服务器上运行它,但是,我想使用~/js/somefile.js
语法.
I don't necessarily need to run it at server, however, I would like to use the ~/js/somefile.js
syntax.
以前,我只是使用绝对路径设置了所有内容,并将项目设置为根级别.因此,我只声明所有样式表,背景图片和javascript文件,例如/css/somefile.css
Previously, I had just set everything with Absolute paths and set my project to be at the root level. SO, I'd just declare all my stylesheets, background images and javascript files something like /css/somefile.css
但是,对于该项目,它不是作为root用户运行的.
However, for this project, it doesn't run as root.
我不能将runat="server"
放在脚本标签上.
I can't put runat="server"
on a script tag.
不过,我可以将其放在链接标签上.
I can put it on a link tag, though.
这肯定是一个常见问题,有几个简单的答案.
This must be a common problem with a few simple answers.
推荐答案
我一直做的是使用普通的script
标签并将src
放入<% %>
标签中,如图所示
What I've always done is use a normal script
tag and put the src
in <% %>
tags, as illustrated here:
<script language="javascript" src='<%=ResolveUrl("~/App_Themes/MainTheme/jquery.js")%>' type='text/javascript'></script>
这篇关于如何使用runat ="server"在asp.Net中的脚本标签上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!