HTML5 Canvas在鼠标点击图片时运行。
& lthtml & gt
& lthead & gt& lt/head & gt;
& ltbody & gt
& ltcanvas id = " canvas " width = " 500 " height = " 500 " style = " border:1px纯红" & gt& lt/canvas & gt;
& lt脚本& gt
var rect={x:100,y:100,w:40,h:20 };//定义要绘制的矩形的位置属性。
var canvas = document . getelementbyid(' canvas ');
var cxt = canvas . get context(' 2d ');
cxt.fillRect(rect.x,rect.y,rect.w,rect . h);//绘制一个矩形
Canvas.onclick=function(e){//向画布添加一个click事件。
e = e | |事件;//获取事件对象
//获取事件在画布中的位置。
var x = e . clientx-canvas . offset left;
var y = e . clienty-canvas . offsettop;
//如果事件位置在矩形区域中
if(x & gt;= rect.x & amp& ampx & lt= rect . x+rect . w & amp;& ampy & gt= rect.y & amp& ampy & lt=矩形y+矩形h){
& lta href="/s?window.open & ampTN = 44039180 _ CPR & amp;fenlei = mv 6 quakxtz n 0 izrqichckpjm 4 NH 00t 1 dbn hm 3 wblp 1 bkuwmlmhkb 0 zwv 5 hcvrjm 3 RH 6 spfkwumw 85 hfynjn 4 NH 6 sgvpst 6 kdthsqpzwytjceqlgcpyw 9 uz 4 bmy-bii 4 wuvye TgN-tlwguv 3 erhn 3n 1 NJ 04 NW 64n 66window.open & lt/a & gt;(‘链接地址’);//打开指定的链接
}
}
& lt/script & gt;
& lt/body & gt;
& lt/html & gt;