アプリ版:「スタンプのみでお礼する」機能のリリースについて

Java Script初心者です。
画像をonclickでロールオーバさせています。
最初の画像をクリックするとロールオーバのイメージになり、その状態でもう1度クリックするとリンクに飛ばすことは出来ますか?

やりたい事は以下のような処理です。

最初の画像→click→ロールオーバーの画像→click→Yahoo!

現在はロールオーバーの画像までは表示できましたが、その画像にリンクを貼ることができません。
色々調べましたら分かりませんでしたので、分かる方がいらっしゃいましたら教えてください。

--------------------------HTML--------------------------

<img src="images/image_01.jpg" id="Image1" alto="EVENT" onclick="MM_swapImage('Image1','','images/image_over_01.jpg',1)" onmouseout="MM_swapImage('Image1','','images/image_01.jpg',1) />





------------------------Java Script--------------------------

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

A 回答 (1件)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">


<title>TwoClickJumper</title>

<p><img src="./img/yahoo0.gif" id="jump01" width="120" height="32" alt="Yahoo?"></p>
<p><img src="./img/google0.gif" id="jump02" width="120" height="32" alt="google?"></p>

<script type="text/javascript">
//@cc_on
(function(){
function TwoClickJumper () {
this.init.apply(this, arguments);
}
TwoClickJumper.prototype.init = function (elmId, image, url) {
var e;
this.count = 0;
this.element = e = document.getElementById(elmId);
this.image0 = (new Image).src = this.element.src;
this.image1 = (new Image).src = image;
this.url = url;
e./*@if(1)attachEvent('on' + @else@*/ addEventListener(/*@end@*/ 'click', (function (cb_) { return function () {
cb_.ms_click();
};})(this), false);
e./*@if(1) attachEvent('on' + @else@*/ addEventListener(/*@end@*/ 'mouseout', (function (cb_) { return function () {
cb_.ms_out();
return;
}})(this), false);
return;
}
TwoClickJumper.prototype.ms_click = function () {
if (this.count == 1) location.href = this.url;
if (this.count == 0) {
this.count++;
this.element.src = this.image1;
this.element.alt = this.image1;
}
return;
}
TwoClickJumper.prototype.ms_out = function () {
this.count = 0;
this.element.src = this.image0;
this.element.alt = this.image0;
return true;
}

new TwoClickJumper('jump01','./img/yahoo1.gif','http://www.yahoo.co.jp/');
new TwoClickJumper('jump02','./img/google1.gif','http://www.google.co.jp/');
})();

</script>
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!