你如何通过从C#变量的JavaScript? [英] How do you pass variables from c# to javascript?

查看:90
本文介绍了你如何通过从C#变量的JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

展望从C#传递变量的JavaScript使用一些jQuery code。经过双打,整数,字符串,数组。有谁知道如何做到这一点?

例如,如果我有在C#这code剪断:

 串等等=这是胡说字符串;

我想这个传递到JavaScript的,这样我可以在jQuery中使用鼠标悬停事件:

  $('#myDiv')鼠标悬停(函数(){//做一些与我的'嗒嗒'串})。


解决方案

算了,我想我想通了。假设上述code,你可以在JavaScript写的:

 <脚本类型=文/ JavaScript的> VAR JavascriptBlah ='<%=布拉赫%GT;'< / SCRIPT>

这将在C#中的嗒嗒传递给JavascriptBlah在客户端。然后你就可以操控客户端上。

Looking to pass variables from c# to javascript to use some jquery code. Passing doubles, ints, strings, arrays. Does anyone know how to do this?

for example if I have this code snip in c#:

string blah = "this is a blah string";

I would like to pass this into javascript so that I could use a mouseover event in jquery:

$('#myDiv').mouseover(function(){ //do something with my 'blah' string });

解决方案

Nevermind I think I figured it out. Assuming the code above, you can write in javascript:

<script type="text/javascript"> var JavascriptBlah = '<%=blah%>'</script>

This will pass the blah in c# to the JavascriptBlah on the client side. Then you can manipulate on client side.

这篇关于你如何通过从C#变量的JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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