javascript正则表达式去除html中的style样式
作者:admin 日期:2020-02-29
一、使用正则表达式去除html富文本中的style样式
String regEx = "style=\"(.*?)\"";
使用到的正则规则
字符 说明
(pattern) 匹配 pattern 并捕获该匹配的子表达式。若要匹配括号字符 ( ),请转义。
. 匹配除”\r\n”之外的任何单个字符。若要匹配包括”\r\n”在内的任意字符,请使用诸如”[\s\S]”之类的模式。
* 零次或多次匹配前面的字符或子表达式。例如,zo* 匹配”z”和”zoo”。* 等效于 {0,}。
? 零次或一次匹配前面的字符或子表达式。例如,”do(es)?”匹配”do”或”does”中的”do”。? 等效于 {0,1}。
结果:
二、使用正则表达式去除指定标签的style属性
操作说明,首先获取指定标签,然后替换标签中的属性
js代码示例如下:
formatImg:function(html){
var newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
var match = match.replace(/style=\"(.*)\"/gi, 'class="img-responsive"');
return match;
});
return newContent;
}
三、同上原理,修改删除指定标签的width属性
//去除table的宽度
content=content.replace(/<table[^>]*>/gi,function(match,capture){
return match.replace(/width=\"(.*)\"/gi,'');
});
centos lnmp重置mysql数据库root密码
作者:admin 日期:2020-02-21
返回顶部的jquery插件
作者:admin 日期:2020-02-16
Easy Peasy
Download the minified version of the plugin, include it after jQuery and:
<script> jQuery(document).ready(function(){ jQuery.goup(); }); </script> 带参数的:点击下载此文件 <script type="text/javascript"> $(document).ready(function () { $.goup({ trigger: 100, bottomOffset: 50, locationOffset: 70,containerColor: '#990000', title: '返回顶部', titleAsText: false }); }); </script>
Demo
Yeah! You can see it in action on this page. If you scroll down, you can see, on the bottom right, the magic!
Options
Name | Description | Type | Default |
---|---|---|---|
location |
On which side the button will be shown ("left" or "right") | String | right |
locationOffset |
How many pixel the button is distant from the edge of the screen, based on the location setted | Integer | 20 |
bottomOffset |
How many pixel the button is distant from the bottom edge of the screen | Integer | 10 |
containerRadius |
Let you transform a square in a circle (yeah, it's magic!) | Integer | 10 |
containerClass |
The class name given to the button container | String | goup-container |
arrowClass |
The class name given to the arrow container | String | goup-arrow |
containerColor |
The color of the container (in hex format) | String | #000 |
arrowColor |
The color of the arrow (in hex format) | String | #fff |
trigger |
After hoiw many scrolled down pixels the button must be shown (bypoassed by alwaysVisible ) |
Integer | 500 |
entryAnimation |
The animation of the show and hide events of the button ("slide" or "fade") | String | fade |
alwaysVisible |
Set to true if u want the button to be always visible (bypass trigger ) |
Boolean | false |
goupSpeed |
The speed at which the user will be brought back to the top ("slow", "normal" or "fast") | String | slow |
hideUnderWidth |
The threshold of window width under which the button is permanently hidden | Integer | 500 |
title |
A text to show on the button mouse hover | String | '' |
titleAsText |
If true the hover title becomes a true text under the button | Boolean | false |
titleAsTextClass |
The class name given to the title text | String | goup-text |
zIndex |
Set the z-index | Integer | 1 |
广告位