首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js高手帮忙 上面代码怎么去点鼠标点击事件

2012-09-25 
js高手帮忙 下面代码如何去点鼠标点击事件/**************************************************示例:HTML

js高手帮忙 下面代码如何去点鼠标点击事件
/**************************************************
示例:
HTML容器:<div id="imgPlayer"></div>
PImgPlayer.addItem( "test1", "http://down.liehuo.net", "http://www.yiiker.com/images/logo1.jpg");
PImgPlayer.addItem( "test2", "http://down.liehuo.net", "http://www.yiiker.com/images/logo2.jpg");
PImgPlayer.addItem( "test3", "http://down.liehuo.net", "http://www.yiiker.com/images/logo3.jpg");
PImgPlayer.init( "imgPlayer", 200, 230 );
***************************************************/
var PImgPlayer = {
_timer : null,
_items : [],
_container : null,
_index : 0,
_imgs : [],
intervalTime : 8000,//轮播间隔时间
init : function( objID, w, h, time )
{

this.intervalTime = time || this.intervalTime;
this._container = document.getElementById( objID );
this._container.style.display = "block";
this._container.style.width = w + "px";
this._container.style.height = h + "px";
this._container.style.position = "relative";
this._container.style.overflow = "hidden";

//this._container.style.border = "1px solid #fff";
var linkStyle = "display: block; TEXT-DECORATION: none;";
if( document.all )
{
linkStyle += "FILTER:";
linkStyle += "progid:DXImageTransform.Microsoft.Wipe(duration=1, motion='forward', GradientSize=1.0) ";
}

var ulStyle = "margin:0;width:"+w+"px;position:absolute;z-index:999;right:5px;FILTER:Alpha(Opacity=20,FinishOpacity=90, Style=1);overflow: hidden;bottom:5px;height:16px; border-right:0";

var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";

var baseSpacStyle = "clear:both; display:block; width:23px;line-height:16px; font-size:12px; FONT-FAMILY:'宋体';opacity: 0.6;margin:2px;";
baseSpacStyle += "border:0;border-right:0;border-bottom:0;";
baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; ";

var ulHTML = "";
for(var i = this._items.length -1; i >= 0; i--)
{
var spanStyle = "";
if( i==this._index )
{
spanStyle = baseSpacStyle + "background:#00a889;";

else {
spanStyle = baseSpacStyle + "background:#4e4e4e;";
}
ulHTML += "<li style=\""+liStyle+"\">";
ulHTML += "<span onmouseover=\"PImgPlayer.mouseOver(this);\" onmouseout=\"PImgPlayer.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"PImgPlayer.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";
ulHTML += "</li>";
}

//var html = "<a href=\""+this._items[this._index].link+"\" title=\""+this._items[this._index].title+"\" target=\"_blank\" style=\""+linkStyle+"\"></a><ul style=\""+ulStyle+"\">"+ulHTML+"</ul>";

var html = ""+this._items[this._index].link+"\" title=\""+this._items[this._index].title+"\" target=\"_blank\" style=\""+linkStyle+"\""<ul style=\""+ulStyle+"\">"+ulHTML+"</ul>";

// var html = "++" <ul style=\""+ulStyle+"\">"+ulHTML+"</ul>";
// alert(html);
   
this._container.innerHTML = html;
var link = this._container.getElementsByTagName("A")[0];


link.style.width = w + "px";
link.style.height = h + "px";
link.style.background = 'url(' + this._items[0].img + ') no-repeat center center';

this._timer = setInterval( "PImgPlayer.play()", this.intervalTime );
},

addItem : function( _title, _link, _imgURL )
{
this._items.push ( {title:_title, link:_link, img:_imgURL } );
var img = new Image();
img.src = _imgURL;
this._imgs.push( img );
},

play : function( index )
{
if( index!=null )
{
this._index = index;
clearInterval( this._timer );
this._timer = setInterval( "PImgPlayer.play()", this.intervalTime );

else {
this._index = this._index<this._items.length-1 ? this._index+1 : 0;
}
var link = this._container.getElementsByTagName("A")[0];
if(link.filters)
{
var ren = Math.floor(Math.random()*(link.filters.length));
link.filters[ren].Apply();
link.filters[ren].play();
}
link.href = this._items[this._index].link;
link.title = this._items[this._index].title;
link.style.background = 'url(' + this._items[this._index].img + ') no-repeat center center';

var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
var baseSpacStyle = "clear:both; display:block; width:23px;line-height:16px; font-size:12px; FONT-FAMILY:'宋体'; opacity: 0.6;margin:2px;";
baseSpacStyle += "border:0;border-right:0;border-bottom:0;";
baseSpacStyle += "color:#fff;text-align:center; cursor:pointer; ";
var ulHTML = "";
for(var i = this._items.length -1; i >= 0; i--)
{
var spanStyle = "";
if( i==this._index )
{
spanStyle = baseSpacStyle + "background:#00a889;";

else {
spanStyle = baseSpacStyle + "background:#4e4e4e;";
}
ulHTML += "<li style=\""+liStyle+"\">";
ulHTML += "<span onmouseover=\"PImgPlayer.mouseOver(this);\" onmouseout=\"PImgPlayer.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"PImgPlayer.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";
ulHTML += "</li>";
}
this._container.getElementsByTagName("UL")[0].innerHTML = ulHTML;
},

mouseOver : function(obj)
{
var i = parseInt( obj.innerHTML );
if( this._index!=i-1)
{
obj.style.color = "#00a889";
}
},

mouseOut : function(obj)
{
obj.style.color = "#fff";
}
}

[解决办法]
我晕你,点击图片会弹出网页,这算什么点击事件???那是由你给出的参数造成的

JScript code
PImgPlayer.addItem( "test1", "http://down.liehuo.net", "b/1.jpg"); 

热点排行