摘要:我们为了浏览方便,我们有的时候要在每一段尾加入“back to top”(回顶部)。

脚本宝典收集整理的这篇文章主要介绍了

javascript代码实例教程-ѧϰJQuery – 15

脚本宝典小编觉得挺不错的,现在分享给大家,也给大家做个参考,希望能帮助你少写一行代码,多一份安全和惬意。

小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

2. 操作DOM

我们为了浏览方便,我们有的时候要在每一段尾加入“back to top”(回顶部)。

js代码

    $('back to top').insertAfter('p.chapter p');  $('').prependTo('body');

前面即是我们要加入的HTML代码,后面是DOM操作(在“p.chapter p”之后插入此HTML代码)。

insertAfter与prependTo虽然都是“之后插入HTML代码”,

但是他们的区别在于一个在是插入Tag的外面、一个是插入Tag的里面。
ѧϰJQuery - 15

在HTML中我们想把所有的“span类名为footnote”包括在一个有序列表中,并且每项内容使用“li”来限定。<"https://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PHByZSBjbGFzcz0="brush:java;"> $('span.footnote').insertBefore('#footer').wrapAll('

    ').wrap('

  1. '); insertBefore在“id为footer”之前插入此HTML代码,包含的内容为wrapAll和wrap。

    wrapAll与wrap的区别,一个为总包;一个为分包。

    例如:

    a

    b

    c

    使用wrapAll('

    '):

    a

    b

    c

    使用wrap('

    '):

    a

    b

    c

    上两段代码实现的效果如下:

    Flatland: A Romance of Many Dimensions

    by Edwin A. Abbott

    Part 1, Section 3

    Concerning the Inhabitants of Flatland

    an excerpt

    Our Professional Men and Gentlemen are Squares (to which class I myself belong) and Five-Sided Figures or Pentagons.

    back to top

    Next above these come the Nobility, of whom there are several degrees, beginning at Six-Sided Figures, or Hexagons, and from thence rising in the number of their sides till they receive the honourable title of Polygonal, or many-Sided. Finally when the number of the sides becomes so numerous, and the sides themselves so small, that the figure cannot be distinguished from a circle, he is included in the Circular or Priestly order; and this is the highest class of all.

    back to top

    It is a Law of Nature with us that a male child shall have one more side than his father, so that each generation shall rise (as a rule) one step in the scale of development and nobility. Thus the son of a Square is a Pentagon; the son of a Pentagon, a Hexagon; and so on.

    back to top

    But this rule applies not always to the Tradesman, and still less often to the Soldiers, and to the Workmen; who indeed can hardly be said to deserve the name of human Figures, since they have not all their sides equal. With them therefore the Law of Nature does not hold; and the son of an Isosceles (i.e. a Triangle with two sides equal) remains Isosceles still. Nevertheless, all hope is not such out, even from the Isosceles, that his posterity may ultimately rise above his degraded condition.…

    back to top

    Rarely―in proportion to the vast numbers of Isosceles births―is a genuine and certifiable Equal-Sided Triangle produced from Isosceles parents. Such a birth requires, as its antecedents, not only a series of carefully arranged intermarriages, but also a long-continued exercise of frugality and self-control on the part of the would-be ancestors of the coming Equilateral, and a patient, systematic, and continuous development of the Isosceles intellect through many generations.

    back to top

    The birth of a True Equilateral Triangle from Isosceles parents is the subject of rejoicing in our country for many furlongs round. After a strict examination conducted by the Sanitary and Social Board, the infant, if certified as Regular, is with solemn ceremonial admitted into the class of Equilaterals. He is then immediately taken from his proud yet sorrowing parents and adopted by some childless Equilateral.

    back to top

    How admirable is the Law of Compensation! By a judicious use of this Law of Nature, the Polygons and Circles are almost always able to stifle sedition in its very cradle, taking advantage of the irrepressible and boundless hopefulness of the human mind.…

    back to top

    Then the wretched rabble of the Isosceles, planless and leaderless, are ether transfixed without resistance by the small body of their brethren whom the Chief Circle keeps in pay for emergencies of this kind; or else more often, by means of jealousies and suspicious skillfully fomented among them by the Circular party, they are stirred to mutual warfare, and perish by one another's angles. No less than one hundred and twenty rebellions are recorded in our annals, besides minor outbreaks numbered at two hundred and thirty-five; and they have all ended thus.

    back to top

    1. "What need of a certificate?" a Spaceland critic may ask: "Is not the procreation of a Square Son a certificate from Nature herself, proving the Equal-sidedness of the Father?" I reply that no Lady of any position will marry an uncertified Triangle. Square offspring has sometimes resulted from a slightly Irregular Triangle; but in almost every such case the Irregularity of the first generation is visited on the third; which either fails to attain the Pentagonal rank, or relapses to the Triangular.
    2. The Equilateral is bound by oath never to permit the child henceforth to enter his former home or so much as to look upon his relations again, for fear lest the freshly developed organism may, by force of unconscious imitation, fall back again into his hereditary level.
    3. And how perfect a proof of the natural fitness and, I may almost say, the pine origin of the aristocratic constitution of the States of Flatland!

      Read the complete text of Flatland.

      附:

      chapter05-2.js

      $(document).ready(function() {     $('back to top').insertAfter('p.chapter p');  $('').prependTo('body');  $('span.footnote').insertBefore('#footer').wrapAll('
        ').wrap('
      1. '); });

        觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

        总结

        以上是脚本宝典为你收集整理的

        javascript代码实例教程-ѧϰJQuery – 15

        全部内容,希望文章能够帮你解决

        javascript代码实例教程-ѧϰJQuery – 15

        所遇到的程序开发问题,欢迎加入QQ群277859234一起讨论学习。如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典网站推荐给程序员好友。 本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。

        80%的人都看过