给img添加onclick属性

ContractedBlock.gif ExpandedBlockStart.gif Code
<script type="text/javascript" language="javascript">
    
function DrawImage(ImgD) 
    {
        
var imgWidth = ImgD.width;
        
var imgHeight = ImgD.height;
        
if (ImgD.width > 830
        {
            
//ImgD.onclick = viewBigImg(ImgD);
            ImgD.width = 830;
            ImgD.height 
= (ImgD.height * 830/ ImgD.width;
            ImgD.title 
= "点击查看大图";
            ImgD.style.cursor 
= "pointer";
            ImgD.setAttribute(
'onclick', document.all ? eval(function() { viewBigImg(this, imgWidth, imgHeight) }) : 'javascript:viewBigImg(this,'+imgWidth+','+imgHeight+')');
        }
    }
    
function viewBigImg(obj, imgWidth, imgHeight) {
        
var iframe = document.getElementById("transbox");
        iframe.style.display 
= "";
        iframe.style.height 
= document.body.scrollHeight + "px";
        iframe.style.width 
= document.body.clientWidth  + "px";
        
var showImg = document.getElementById("showImgImg");
        showImg.src 
= obj.src;
        showImg.style.display 
= "";
        showImg.style.left 
= (document.body.clientWidth / 2 - imgWidth / 2+ "px";
        showImg.style.top 
= document.documentElement.scrollTop + document.documentElement.clientHeight / 2 - imgHeight / 2 + "px";
        
return false;
    }
    
function hideImgImg() {
        
var iframe = document.getElementById("transbox");
        iframe.style.display 
= "none";
        
var showImg = document.getElementById("showImgImg");
        showImg.style.display 
= "none";
    }

</script>
<div id="transbox" style="display:none;position:absolute; margin:0px;left:0px; top:0px;margin: 0 0px;background-color: #000;border: 2px solid black;filter:alpha(opacity=80);opacity: 0.8;-moz-opacity:0.8;"></div><img id="showImgImg" src="" onclick="hideImgImg();" title="单击关闭" style="display:none;position:absolute;filter:alpha(opacity=100);opacity: 1;-moz-opacity:1;z-index:100;"/>


ContractedBlock.gif ExpandedBlockStart.gif Code
string allText = dr["contents"].ToString();
        allText 
= Regex.Replace(allText, @"<img(?=.*?src=(['""])(?<content>[^""]*)\1)\s+(?:\w+=""[^""]*""\s*)*[^>]*>(?:</img>)?"@"<img src=""${content}"" οnlοad=""javascript:DrawImage(this);"" border=""0"">", RegexOptions.IgnoreCase);//" οnclick=""return viewBigImg(this);"" style=""cursor: pointer;"

转载于:https://www.cnblogs.com/pwqzc/archive/2008/10/27/1320252.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值