从div中的代码隐藏调用JavaScript [英] Calling javascript from codebehind in div

查看:63
本文介绍了从div中的代码隐藏调用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在aspx页面中有一个标签,并且我将其代码从后台代码设置为:

Hi I have a label in aspx page and i am setting its text from code-behind as :

label.text= "<image  önclick=''javascript:show(''" + imagename + "'')''/>";



我在首页中将JavaScript定义为



And i am having JavaScript defined in my master page as

<script type=javascript>

    function show(image) {
alert(image);
}
</script>


但这却给了我运行时错误,并且没有调用JavaScript.

有人可以告诉我我该怎么解决.


But then it gives me runtime error and JavaScript isn''t called.

Can someone tell me how can i solve this.

推荐答案

尝试一下:
Try it this way:
label.Text= "<image  onclick=\"javascript:show('" + imagename + "')\"/>";



onclick中有一个ö,Java脚本中的引号被弄乱了.标签的text属性以大写字母t开头.除此之外,您不应该滥用标签来输出图像标签.您可以为此使用asp:literal标签,也可以仅使用图片标签,因为这就是它的目的.

希望有帮助.

干杯!



There was an ö in onclick and the quotes in java script were messed up to. The text property of the label starts with a capital t. Besides that you shouldn''t abuse a label to ouput an image tag. You could use an asp:literal tag for that or just use an image tag because that''s what it was meant for.

Hope that helps.

Cheers!


看看这篇CP文章,
使用&调用RegisterStartUpScript,RegisterClientScript和客户端脚本 [ ^ ]
Have a look on this CP article,
Use & Call RegisterStartUpScript, RegisterClientScript and Client-Side Script[^]


这篇关于从div中的代码隐藏调用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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