我需要用 app.config 中的值填充变量。有没有办法在 JavaScript 中做到这一点?这就是我现在所拥有的,但我不相信它是正确的..
var notConfident = ConfigurationManager.AppSettings["GoogleValue"];
最佳答案
不,JavaScript 在客户端浏览器中运行,应用程序配置是服务器中的一个文件。
您可以通过将其发送到客户端来获取该值,例如:
.aspx 文件:
<input type="hidden" id="ikey" runat="server" />
.cs文件,页面加载方式:
ikey.InnerText = ConfigurationManager.AppSettings["GoogleValue"];
.js文件,onload方法:
var something = document.getElementById("ikey").value;
关于javascript - 在 Javascript 中访问 app.config 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14286130/