在ASP页面中使用javascript变量和#include的正确语法是什么 [英] What is correct syntax with javascript variable and #include in ASP page

查看:90
本文介绍了在ASP页面中使用javascript变量和#include的正确语法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何将 JavaScript变量 #include 声明一起使用



我似乎无法忍受为了得到正确的语法,如果它是可能的



谢谢



我试过的:



< div id =vcontainerrunat =server> 
< script type =text / javascript>
// var srcFile = getmmView('<%#Container.EvalDataItem(FileName_wo_ext)%>');
var srcFile =〜/ Views / D1C1.html<<上面的函数返回一个像这样的字符串

//这个工作<! - #include virtual =〜 /Views/D1C1.html - >
//这不是<! - #include virtual = + srcFile + - >
//这不是document.write(<! - #include virtual ='+ srcFile +' - >)

< / script>
< / div>

解决方案

您尝试做的事情是不可能的。 #include 在服务器上处理,而Javascript在上处理 >您的页面已执行并发送了响应。



您无法使用客户端上运行的代码修改服务器上发生的事件以生成包含客户端的页面 - 代码!



您需要找到一种不同的方式来满足您的要求。例如,您可以使用jQuery的 .load() [ ^ ]或 ajax() [ ^ ]根据需要从服务器加载内容的方法。

Anyone know how to use JavaScript variable with an #include statement

I can't seem to get the syntax right, if it's even possible

thanks

What I have tried:

<div id="vcontainer" runat="server" >
 <script type="text/javascript">
//var srcFile = getmmView('<%# Container.EvalDataItem("FileName_wo_ext") %>');
      var srcFile = "~/Views/D1C1.html"  <<above function returns a string like this

// this works <!--#include virtual="~/Views/D1C1.html" -->
//this doesn't  <!--#include virtual=+srcFile+ -->
//this doesn't  document.write("<!--#include virtual='"+srcFile+ "'-->")

</script>
</div>

解决方案

What you're trying to do is not possible. #include is processed on the server, whereas Javascript is processed on the client, after your page has executed and sent the response.

You can't use code running on the client to modify what happened on the server to generate the page containing the client-side code!

You'll need to find a different way to achieve your requirements. For example, you could use jQuery's .load()[^] or ajax()[^] methods to load content from the server on demand.


这篇关于在ASP页面中使用javascript变量和#include的正确语法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆