最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Can I use a VB variable inside of an Embedded Javascript section? - Stack Overflow

programmeradmin4浏览0评论

Is it possible to do something like this:

<% Dim foo as string = "bar" %>

<script type="text/javascript">
    var baz = <%=foo %>
</script>

Where the <script> tag is embedded on my index page?

Is it possible to do something like this:

<% Dim foo as string = "bar" %>

<script type="text/javascript">
    var baz = <%=foo %>
</script>

Where the <script> tag is embedded on my index page?

Share Improve this question asked Nov 5, 2008 at 14:26 AndersAnders 12.6k36 gold badges101 silver badges146 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

Yes, but make sure you put quotes around it and a semicolon:

var baz = '<%=foo %>';
发布评论

评论列表(0)

  1. 暂无评论