从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[^]