Js implements exquisite code for 9-9 multiplication tables

Source: Internet
Author: User
This article mainly introduces the sample code for js to implement the gorgeous 9-9 multiplication table effect. It has good reference value. Let's take a look at it below. This article mainly introduces the sample code for js to implement the gorgeous 9-9 multiplication table effect. It has good reference value. Let's take a look at it together with the small Editor.

:

The Code is as follows:

 
  Multiplication Table implemented by span Script function multiplication (a) {var str ='

'; For (var I = 1; I <= a; I ++) {for (var j = 1; j <= I; j ++) {var curstr = j + 'X' + I + '=' + I * j; j! = I? Str + = ''+ curstr +'': str + = ''+ curstr +'
';} Str + ="

"; Document. write (str);} I multiplication (9); var oSpans = document. getElementsByTagName ("span"); for (var I = 0; I <oSpans. length; I ++) {oSpans [I]. onclick = function () {// alert ("I am the first" + parseInt (this. innerHTML) + "line"); alert (this. innerHTML + "I am in the" + this. innerHTML. charAt (4) + "row");} oSpans [I]. onmouseover = function () {// console. log (111); var num = this. innerHTML. charAt (4); // console. log (num); for (var j = 0; j <oSpans. length; j ++) {if (oSpans [j]. innerHTML. charAt (4) = num) {oSpans [j]. classList. add ("hover") ;}} this. classList. add ("only");} oSpans [I]. onmouseout = function () {var num = this. innerHTML. charAt (4); for (var j = 0; j <oSpans. length; j ++) {if (oSpans [j]. innerHTML. charAt (4) = num) {oSpans [j]. classList. remove ("hover") ;}} this. classList. remove ("only") ;}} script

The above is the details of js Code for implementing exquisite 9-9 multiplication tables. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.