Skip to content

Instantly share code, notes, and snippets.

@tingwei628
Last active December 7, 2015 09:48
Show Gist options
  • Save tingwei628/3600d927fb7b2a66baaf to your computer and use it in GitHub Desktop.
Save tingwei628/3600d927fb7b2a66baaf to your computer and use it in GitHub Desktop.
[JavaScript][ExtJS]如何將 ExtJS 的htmleditor 裡面的style 簡單化 (simplify the style inside the htmleditor)
paste: {
element: 'inputEl',
fn: function(event, inputEl) {
var a = add_Content.getValue();
//已過濾表格 儲存在var b
var b = a.replace(/((<td[^>]+)style=".*?">)/ig, function(x) {
return x = x.replace(/style=".*?"/, 'style="border:solid"');
});
//對非td 的style 改變,儲存在c
var c = b.replace(/((<[^td][^>]+)style=".*?">)/ig, function(y) {
y = y.replace(/style=".*?"/, 'style=""');
return y;
});
add_Content.setValue(c);
}
}
@tingwei628
Copy link
Author

補充說明: 如何移除Html tag, 取得裡面的文字
(參考:http://stackoverflow.com/questions/11229831/regular-expression-to-remove-html-tags-from-a-string)
例如:

<font face="null">OKKK</font>
   移除tag後, 變成只有OKKK
var text = '<font face="null">OKKK</font>';
text.replace(/<[^>]*>/g, "");

@tingwei628
Copy link
Author

同上, 但多了過濾"&nbsp"
參考:http://stackoverflow.com/questions/1499889/remove-html-tags-in-javascript-with-regex

//s 是一連串的html 
s.replace(/(&nbsp;|<([^>]*)>)/ig,'')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment