modalDialog的使用,圖片切換,點擊圖片時開啟一個表單,並顯示資訊

來源:互聯網
上載者:User

標籤:java   使用   width   os   javascript   html   

//主表單

//與open的區別:1、參數二是傳遞的參數 2、屬性設定格式:屬性=屬性值; 3、dialogHeight與dialogWidth沒有單位,即需要自己加上px

 //window.showModalDialog

//("modalDialog.html",window,"dialogHeight=300px;dialogWidth=300px;scroll=yes;status=yes;dialogTop=100;dialogLeft=100;resizable=1");

<script language="javascript" type="text/javascript">
 //圖片的描述
 var names=[["貓","這是只好貓"],["籃球運動員","非常強"],["登入","歡迎"],["書","好好讀書"]];
 //圖片地址
 var imgs=["img//cat1.gif","img\\xiaoniu.jpg","img//login.jpg","img//書END.jpg"];
 //索引
 var index=1;
 //圖片自動切換
 function changeImg(){
  if(index==4){
   index=0;
  } 
  document.getElementById("img").src=imgs[index];
  index++;
 }
 //點擊span切換圖片
 function clickSpan(){
  var spans=document.getElementsByTagName("span"); 
  for(var i=0;i<spans.length;i++){

//為每個span標籤添加一個點擊事件
   spans[i].onclick=function(){
     index=this.innerHTML-1;
     document.getElementById("img").src=imgs[index];
   };
  }
 }
 
 window.onload=clickSpan;
 window.setInterval("changeImg()",1000);
</script>

<body>  

<p align="center">圖片動態轉場效果</p>

<img src="img/cat1.gif" id="img" width="160" height="160" onclick="javascript:window.showModalDialog(‘hw1_Hw2_1.html‘,window)"/><br />

  <span>1</span>        

<span>2</span>        

<span>3</span>        

<span>4</span>    

</body>

 

//開啟的表單

<script language="javascript" type="text/javascript">
     function show(){
   //擷取開啟這個表單的表單對象
   var win= window.dialogArguments;
   //擷取表單對象中的names數組的元素
   var name=win.names[win.index-1];
   //擷取表單對象的url數組的元素
   //第一種方法
   //var url=win.imgs[win.index-1];
   //第二種方法
   //var url=win.document.getElementById("img").src;
   document.writeln("<img src=‘"+url+"‘ width=‘260‘ height=‘300‘ align=‘left‘/>");
   document.write("名稱:"+name[0]+"<br>");
   document.write("描述:"+name[1]+"<br>");

 

 //window.dialogArguments擷取開啟本模式表單的表單
  //window.dialogArguments.location.href="開啟表單以及父表單重新整理.html";//重新整理
  //window.close();//關閉
  }
  window.onload=show;
    </script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.