你如何将变量从 c# 传递给 javascript? [英] How do you pass variables from c# to javascript?

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

问题描述

希望将变量从 c# 传递到 javascript 以使用一些 jquery 代码.传递双精度、整数、字符串、数组.有人知道怎么做吗?

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?

例如,如果我在 c# 中有此代码片段:

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

string blah = "this is a blah string";

我想将其传递给 javascript,以便我可以在 jquery 中使用鼠标悬停事件:

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 });

推荐答案

没关系,我想我想通了.假设上面的代码,你可以用javascript编写:

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

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

这会将 c# 中的 blah 传递给客户端的 JavascriptBlah.然后你可以在客户端进行操作.

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天全站免登陆