如何分配ASP.NET的隐藏字段值的JavaScript变量? [英] How to assign ASP.NET hidden field value to JavaScript variable?
问题描述
以下是摘自code片段
<一href=\"http://pietschsoft.com/post/2011/09/09/Tag-Editor-Field-using-jQuery-similar-to-StackOverflow.aspx\" rel=\"nofollow\">http://pietschsoft.com/post/2011/09/09/Tag-Editor-Field-using-jQuery-similar-to-StackOverflow.aspx
Following is the code snippets taken from http://pietschsoft.com/post/2011/09/09/Tag-Editor-Field-using-jQuery-similar-to-StackOverflow.aspx
// pre-selected tags
values: [
'javascript',
'css',
'jquery'];
我要分配值
一些隐藏字段或C#变,请大家帮忙,我没有使用JavaScript / jQuery的专业知识。
I want to assign values
with some hidden field or C# variable, please help as I don't have expertise with JavaScript/jQuery.
推荐答案
您可以创建一个公共财产,并用它在你的HTML像下面...
You can create a public property and use it in your HTML like the following...
C#(元/添加注释)
public string Choices { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
string[] choices = new string[] { "'Choice 1'", "'Choice 2'", "'Choice 3'" };
Choices = String.Join(",", choices);
}
的JavaScript
<script type="text/javascript">
var values = [<%= Choices %>];
</script>
请注意:我把周围的数值单引号,因为JavaScript的要求他们承认值作为一个字符串数组(有效 = ['值','值'] / 的一部分无效 = [值,值])。
NOTE: I put single quotes around the values since JavaScript requires the them to recognize the value as part of a string array ( Valid = ['value','value'] / Invalid = [value,value] ).
这篇关于如何分配ASP.NET的隐藏字段值的JavaScript变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!