使用JavaScript,如何找到具有font-style: italic
(除了<i>
和<em>
)的每个元素,并将其切换到font-style: normal
,如果元素包含一个或多个非拉丁字符([a-zA-Z]
)?
$('selector_for_text_containers').each(function(){
var str = $(this).attr('style').replace('italic', 'normal');
$(this).attr('style', str);
});
您可以在此函数中使用@Loyalty Technology给出的方法来测试字符是否可用。
function validate() {
var chars = 'άλφα';
$.each( $('.text') , function (indx, elm) {
var text = $(elm).text().split('');
text.forEach( function( letter, ind ) {
if ( chars.indexOf(letter) !== -1) {
var str = $(this).attr('style').replace('italic', 'normal');
$(elm).attr('style', str);
}
});
});