茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    JavaScript實(shí)現(xiàn)復(fù)制或剪切內(nèi)容到剪貼板功能的方法
    來(lái)源:易賢網(wǎng) 閱讀:1228 次 日期:2016-06-25 11:26:40
    溫馨提示:易賢網(wǎng)小編為您整理了“JavaScript實(shí)現(xiàn)復(fù)制或剪切內(nèi)容到剪貼板功能的方法”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了JavaScript實(shí)現(xiàn)復(fù)制或剪切內(nèi)容到剪貼板功能的方法,我們平時(shí)看到的網(wǎng)頁(yè)上很多一鍵復(fù)制功能就是如此實(shí)現(xiàn),需要的朋友可以參考下

    項(xiàng)目中需要實(shí)現(xiàn)一個(gè)點(diǎn)擊按鈕復(fù)制鏈接的功能,網(wǎng)上看到的幾款插件,ZeroClipboard是通過(guò)flash實(shí)現(xiàn)的復(fù)制功能,隨著越來(lái)越多的提議廢除flash,能不能通過(guò)JS來(lái)實(shí)現(xiàn)復(fù)制剪切呢,今天分享一個(gè)兼容IE7瀏覽器復(fù)制的插件給大家,支持使用javascript實(shí)現(xiàn)復(fù)制、剪切和粘貼。

    方法。

    復(fù)制

    var copy = new clipBoard(document.getElementById('data'), {

      beforeCopy: function() {

      },

      copy: function() {

        return document.getElementById('data').value;

      },

      afterCopy: function() {

      }

    });

    復(fù)制將自動(dòng)被調(diào)用,如果你想要自己調(diào)用:

    var copy = new clipBoard(document.getElementById('data'));

    copy.copyd();

    document.getElementById('data') :要獲取的對(duì)象, 你也可以使用jQuery $('#data')

    剪切

    基本上與復(fù)制的實(shí)現(xiàn)方法相同:

    var cut = new clipBoard(document.getElementById('data'), {

      beforeCut: function() {

      },

      cut: function() {

        return document.getElementById('data').value;

      },

      afterCut: function() {

      }

    });

    或者

    var cut = new clipBoard(document.getElementById('data'));

    cut.cut();

    paste

    var paste = new clipBoard(document.getElementById('data'), {

      beforePaste: function() {

      },

      paste: function() {

        return document.getElementById('data').value;

      },

      afterPaste: function() {

      }

    });

    或者

    var paste = new clipBoard(document.getElementById('data'));

    paste.paste();

    完整代碼:

    (function(name, fun) {

      if (typeof module !== 'undefined' && module.exports) {

        module.exports = fun();

      } else if (typeof define === 'function' && define.amd) {

        define(fun);

      } else {

        this[name] = fun();

      }

    })('clipBoard', function() {

      "use strict";

      function clipBoard(tar, options) {

        this.options = options || {};

        this.tar = tar[0] || tar;

        // if options contain copy, copy will be applied soon

        if (this.options.copy) {

          this.copyd();

        }

        if(this.options.cut) {

         this.cut();

        }

        if(this.options.paste) {

         this.paste();

        }

      }

      clipBoard.prototype.copyd = function(value) {

        // before the copy it will be called, you can check the value or modify the value

        if (this.options.beforeCopy) {

          this.options.beforeCopy();

        }

        // if the options set copy function, the value will be set. then get the paramer value.

        // above all, if the value is null, then will be set the tar of value

        value = value || this.tar.value || this.tar.innerText;

        if (this.options.copy) {

          value = this.options.copy();

        }

        // for modern browser

        if (document.execCommand) {

          var element = document.createElement('SPAN');

          element.textContent = value;

          document.body.appendChild(element);

          if (document.selection) {

            var range = document.body.createTextRange();

            range.moveToElementText(element);

            range.select();

          } else if (window.getSelection) {

            var range = document.createRange();

            range.selectNode(element);

            window.getSelection().removeAllRanges();

            window.getSelection().addRange(range);

          }

          document.execCommand('copy');

          element.remove ? element.remove() : element.removeNode(true);

        }

        // for ie

        if (window.clipboardData) {

          window.clipboardData.setData('text', value);

        }

        // after copy

        if (this.options.afterCopy) {

          this.options.afterCopy();

        }

      };

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)