meili 发表于 2022-10-27 16:01:56

如何用JS输出图片img的title<divclass="box"id="box"><ahref="#"class="pic1"><imgsrc="1.j

<p>问题:如何用JS输出图片img的title&lt;divclass=&quot;box&quot;id=&quot;box&quot;&gt;&lt;ahref=&quot;#&quot;class=&quot;pic1&quot;&gt;&lt;imgsrc=&quot;1.j
<p>答案:↓↓↓<p class="nav-title mt10" style="border-top:1px solid #ccc;padding-top: 10px;">李玉俭的回答:<div class="content-b">网友采纳  <HEAD>  <TITLE>如何通过JS实现鼠标经过图片1.gif2.gif3.gif4.gif的时候动态的提取这些图片的title指到box2中 </TITLE>  <style type="text/css">  .on{padding15px 10px; font-weightbold;colorred;}  .off{padding0px 0px; font-weightthin;colorblack;}  </style>  <script type="text/javascript" src="jquery-1.8.0.js"></script>  <script type="text/javascript" src="jquery-1.8.0.min.js"></script>  <script>  jQuery(function($) {  $('#box img').each(function(){  $(this).bind('mouseenter mouseleave',function(){  var t = '|'+this.title+'|';  if($("#box2").text().indexOf(t)==-1)  {  $("#box2").text($("#box2").text()+t);  }  });  });  });  </script>  </HEAD>  <BODY>  <divclass="box"id="box">  <a href="#"class="pic1">  <img src="mouse_dragimagesb.gif" title="1" />  </a>  <a href="#"class="pic2">  <img src="mouse_dragimagesb.gif" title="2" />  </a>  <a href="#"class="pic3">  <img src="mouse_dragimagesp.gif" title="3" />  </a>  <a href="#"class="pic4">  <img src="mouse_dragimagesg.gif" title="4" />  </a>  </div>  <divclass="box2"id="box2"></div>  </BODY>
页: [1]
查看完整版本: 如何用JS输出图片img的title&lt;divclass=&quot;box&quot;id=&quot;box&quot;&gt;&lt;ahref=&quot;#&quot;class=&quot;pic1&quot;&gt;&lt;imgsrc=&quot;1.j