Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IE11/Edge的“styleWithCSS”有任何替代品吗?_Javascript_Html_Css_Internet Explorer_Microsoft Edge - Fatal编程技术网

Javascript IE11/Edge的“styleWithCSS”有任何替代品吗?

Javascript IE11/Edge的“styleWithCSS”有任何替代品吗?,javascript,html,css,internet-explorer,microsoft-edge,Javascript,Html,Css,Internet Explorer,Microsoft Edge,我知道有两个帖子是关于这个的,但是一个不是我想要的,另一个是,但是已经7年了。也许现在有一些已知的方法 我使用的是Summernote.js编辑器,在内部,只要您想将文本向左、居中或向右对齐,它就会执行document.execCommand'command',false,value。 问题是,对于Firefox和IE/Edge,这与WebKit中的工作方式不同。每个浏览器都有自己的行为方式。 Chrome添加了与文本align:direction内联的样式,Firefox和IE/Edge添加了

我知道有两个帖子是关于这个的,但是一个不是我想要的,另一个是,但是已经7年了。也许现在有一些已知的方法

我使用的是Summernote.js编辑器,在内部,只要您想将文本向左、居中或向右对齐,它就会执行document.execCommand'command',false,value。 问题是,对于Firefox和IE/Edge,这与WebKit中的工作方式不同。每个浏览器都有自己的行为方式。 Chrome添加了与文本align:direction内联的样式,Firefox和IE/Edge添加了一个名为align='direction'的属性

经过一些调查,我发现您可以使用命令styleWithCSS来转换那些不推荐使用的样式?属性转换为内联样式属性。这是完美的,但它只适用于Firefox

document.execCommand("styleWithCSS", 0, true);
看起来这仍然不受Microsoft浏览器的支持,无论您将什么值作为参数传递,上面控制台中的返回值始终为false


是否有已知的替代品

因此,我通过仅针对IE和Edge在编辑器中迭代元素,并将align属性更改为style inline with text align,成功地实现了这一点。 该方法的外观如下所示:

var styleWithCSSIE = this.styleWithCSSIE = function() {
      if(/MSIE 10/i.test(navigator.userAgent) || /Edge\/\d./i.test(navigator.userAgent)) {
        var items = $(".note-editable *");
        $.each(items, function(i, element) {
          var $elem = $(element);
          var align = $elem.attr('align') || undefined;

          if(!align) {
            return;
          }

          $elem.css('text-align', align);
          $elem.removeAttr('align');
        });
      }
    };

在summernote.js执行document.execCommandsCmd后使用它,false,value

很好。document.execCommand的规划和实现一直很差。这是一个跨浏览器的噩梦。是的,我得到了图书馆github上某个人的帮助。这简直快把我逼疯了!现在我想解决一个关于FF和Edge标题的“粗体”问题。又是一场噩梦。