我找到了一个 javascript
code获取和设置图像的尺寸。
通过引用此链接,我在 asp.net
中编写了代码网站喜欢这个,
<img runat="server" id="MyImage" onload="if( this.width >
this.height ){ this.width = 400; this.height = 600} else {this.width = 600;
this.height=400}" />
我想知道的是这个javascript
怎么写<script>
中的代码标记
<script type="text/javascript">
function setDimension() {
}
</script>
最佳答案
试试这个
Javascript:
<script type="text/javascript">
function setDimension(me) {
var th= document.getElementById(me);
if( th.width >
th.height ){ th.width = 400; th.height = 600} else {th.width = 600;
th.height=400}
}
</script>
ASPX代码:
<img runat="server" id="MyImage" />
在code behind中,onload也是一个server event,需要在server image control中添加custom attribute
MyImage.Attributes["onload"] = "setDimension(this.id)";
关于c# - 在javascript函数中使用asp.net的图像组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16494100/