简体   繁体   English

在dom准备使用js更改html源

[英]on dom ready change html source using js

I'm stuck with tinymce align problem. 我遇到了tinymce align问题。 When I align text content to image let say left content preview look ok but on rendering content I'm getting source like this 当我将文本内容与图像对齐时,可以说左侧内容预览看起来不错,但是在渲染内容时,我会像这样

<p>
   <img width="205" height="154" alt="" src="/Content/uploads/images/mypic.jpg" left;"="">
</p>

now I want to change this snippet left;"=" to align="left" using javascript so when user loads page and when js recognize snippet left;"=" to automatically change to valid align property align="left" . 现在,我想使用javascript将此代码段left;"="更改为align="left"以便在用户加载页面时,当js识别到left;"="以自动更改为有效的align属性align="left"

How to do that? 怎么做?

I haven't seen anything like this left;"=" generated automatically. 我还没有看到这样的东西left;"="自动生成。 I'm not sure why it is generated, but you can remove the left attribute and add align attribute to your image . 我不确定为什么会生成它,但是您可以删除left属性并将align属性添加到image

Better try like this, 最好这样尝试

 $(document).ready(function(){
    if($('img').attr("left")) {
      $(this).removeAttr( 'left');
      $(this).attr("align","left");
    }
 )};

When I test this, you end up with an empty left;" attribute on the image, so you can do this: 当我对此进行测试时,您最终在图像上left;"了一个空的left;"属性,因此您可以执行以下操作:

if ($('img').attr('left;"') !== undefined) {
    $('img').attr('align', 'left');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM