无为清净楼资源网 Design By www.qnjia.com

该小脚本实现的是对输入框内容中取出<img>标签中的src中的内容,然后在原来位置进行替换内容,然后在去除输入内容中的html标签,空格等操作

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <script>
    window.onload = function () {
      var target = document.getElementById("div1");
      var but = document.getElementById("but");
      var value;
      but.onclick = function () {
        value = target.innerHTML;
        result = dealText(value);
        alert(result);
      };
    };

    function dealText(msg) {
      var text1 = imageRound(msg);
      var text2 = removeTag(text1);
      var text3 = removeBlank(text2);
      var text4 = changeNBSP(text3);
      return text4;
    }


    function DealNum(num) {
      var content = [];
      for (var i = 0; i < num.length; i++) {
        //
        content.push(defaultSrc(num[i]));
      }
      return content;
    }

    function defaultSrc(src) {
      return ':avator:';
    }

    function returnValue(srcValue) {
      var num = [];
      var pattern = /([^\/]+)\./;
      var src;
      for (var i = 0; i < srcValue.length; i++) {
        src = pattern.exec(srcValue[i])[1];
        num.push(src);

      }
//      alert(num);
      var source = DealNum(num);
      return source;

    }


    function imageRound(text) {
      var reg2 = /<img.*"");
      return text1;
    }

    function removeBlank(text) {
      var text1;
      var reg = /\s+/g;
      text1 = text.replace(reg, "");
      return text1;
    }

    function changeNBSP(text) {
      var text1;
      var reg = /&nbsp/g;
      var reg1 = /\;/g;
      text1 = text.replace(reg, ' ');
      text1 = text1.replace(reg1, "");
      return text1;
    }
  </script>
</head>
<body>
<div contenteditable="true" id="div1">abc&nbspefg&nbsp<img src="/UploadFiles/2021-04-02/123.jpg">

标签:
正则表达式,输入内容,进行处理

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com