SoFunction
Updated on 2025-02-28

Js classic case example code

This article tells the story of JS implementing mouse hover to switch pictures, displaying weather forecasts, and using focus to select website example codes. It is shared with you for your reference. The details are as follows:

Mouse hover to switch pictures:

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
('b1').src =""
}
function mouseOut()
{
('b1').src =""
}
</script>
</head>
<body>
<a href="#" 
onmouseover="mouseOver()" onmouseout="mouseOut()">
<img alt="Visit W3School!" src=""  onmouseover="alert('Your mouse is on the picture!  ')")/>
</a>
</body>
</html>

js displays weather forecast:

<html>
<head><title></title>
<script type="text/javascript">
</script>
</head>
<body >
<div>
<iframe src="/m/pn11/" width="480" height="70" frameborder="1"></iframe>
</div>
</body>
</html>

js uses focus to select websites:

&lt;html xmlns="http:///1999/xhtml"&gt;
&lt;head&gt;
 &lt;title&gt;&lt;/title&gt;
 &lt;script type="text/javascript"&gt;
  var i = 1;
  var focusid;
  function defau() {
   ('1').focus();
   focusid=1;
  }
  function showtable() {
   var id = i + 1;
   (id).focus();
   focusid=id;
   i++;
   if (i == 4) {
    i = 0;
   }
  }
  function openhref() {
   var href = (focusid).href;
    = href;
  }
 &lt;/script&gt;
&lt;/head&gt;
&lt;body onload="defau()"&gt;
&lt;a href="/" &gt;Baidu&lt;/a&gt;
&lt;a href="/" &gt;Google&lt;/a&gt;
&lt;a href="/" &gt;Youku&lt;/a&gt;
&lt;a href="/" &gt;Potato&lt;/a&gt;
 &lt;input  type="button" value="choose" onclick="showtable()" /&gt;&lt;br /&gt;
 &lt;input  type="button" value="Enter" onclick="openhref()" /&gt;
&lt;/body&gt;
&lt;/html&gt;

The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.