的事情是,你不能只用JS服务器端通信时,JS是一个客户端,这样你就不会得到你所创建的变量在ServerSide中。
为了得到他们,你会需要:
<%= write_the_thing_here %>
为您的代码,你会写:
string someThing = "<%= HttpUtility.HtmlEncode(Request.QueryString[0]) %>";
// now use this someThing in the document..you can use var instead of string
// but not them both..
document.getElementById(someThing);
// note the semicolon on the end, to close it..
,则不应使用string var
,因为他们是在JavaScript中的数据类型和ASP.NET一样,所以代码可能会困惑,想到这到底是什么。取而代之的是
,你也可以尝试写一个隐藏的输入字段作为
<input type="hidden" name="someThing" value="@Request.QueryString[0]" />
然后用它做你想要做动态什么都。如果你真的想使用服务器的ID,这可能是这样做的简单方法。
关于jQuery的哥们
对不起:
var someThinge = $('input[type="hidden"]').val();
,然后继续你的工作!
帮助笔记Alexei Levenkov:JavaScript中的分号是可选的。它们的主要用途是区分由混淆器/最小化工具(工具或人)或正常开发人员编写的代码:)
然后呢?你的问题到底是什么?顺便说一句:'var'是一个Javascript关键字 - 将它改为'myVar',或者其他有意义的东西。 – 2013-10-19 22:26:21
我更新了我的问题,使我要求更清楚。 – Kevin