从asp.net传递价值的javascript [英] Passing value to javascript from asp.net
本文介绍了从asp.net传递价值的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<script type="text/javascript">
function abc()
{
var id = document.getElementById('123');
var caption= <%=MyProperty %>;
}
</script>
背后code:
protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterStartupScript(Guid.NewGuid().ToString(),"<script language = 'javascript'>abc();</script>");
}
protected int MyProperty
{
get
{
return 123;
}
}
我需要字符串值传递给JavaScript,为int这个codeS工作正常。
i need to pass string value to javascript, with int this codes works fine.
protected string MyProperty
{
get
{
return "123";
}
}
当我试图通过这串code简化版,作品。
when i tried to pass string this code does't works.
推荐答案
如果你需要传递一个String您必须指定分隔符或
if you need to pass a String you have to specify the delimiters " or '
var caption= "<%=MyProperty %>";
或
var caption= '<%=MyProperty %>';
没有他们的JavaScript间$ P $ myProperty的PTS的字符串值作为一个Javascript变量的名字。
without them the javascript interprets the string value of MyProperty as the name of a Javascript variable.
这篇关于从asp.net传递价值的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文