zoukankan      html  css  js  c++  java
  • JS 单击复制文本

    target.select():选中target需为Input
    document.execCommand("copy"):复制
    window.getSelection().empty():清空选中状态
    input需要设readonly=true,但不能设置disabled=true

      /*
        Dart.js
      */
    
      buildDetailTopItemForCopy("${conf.Lang.lang_cn["PRINCIPAL"]} : ",k2data?.contact, this._onCopyClick)
      
      Element buildDetailTopItemForCopy(
        String key, String value, ClickHandler clickHandler) {
        return Element.div()
          ..children.addAll([
            Element.span()..text = key,
            InputElement()
              ..value = (null == value ? "" : value)
              ..readOnly = true
              ..onClick.listen(clickHandler)
          ]);
      }
    
      void _onCopyClick(MouseEvent e) {
        print("_onCopyClick");
        InputElement target = e.target as InputElement;
        if (target.value == "") return;
        target.select();
        document.execCommand("copy");
        try {
          var copyResult = document.execCommand('copy');
          print("copy result::${copyResult}");
          if (copyResult)
            this._vm.popupModal("/toast", data: ToastIntent(""${target.value}"复制成功"));
        } catch (err) {
          print("copy err::${err}");
        }
        window.getSelection().empty();
      }
    
  • 相关阅读:
    听说,好久不更了......
    JavaScript中数组常用方法
    html5常用英语单词
    重写与重载的区别
    RelativeLayout以及ListView
    树莓派基础配置
    通过yum安装lnmp-phpmyadmin
    POJ1850
    基于字典序的组合生成算法
    全排序之字典排序
  • 原文地址:https://www.cnblogs.com/yanjiez/p/14709169.html
Copyright © 2011-2022 走看看