English 中文(简体)
突出具有大胆、强调、印章风格的案文
原标题:Highlight the text which has bold, underline, Italic styles

我怎么能寻找下文所列任何特性的文本。

 .css( font-weight ,  bold );
 .css( font-style ,  italic );
 .css( text-decoration ,  underline );
 <b> Some Text </b>
 <u> Some Text </u>
 <i> Some Text </i>

我想取代案文。

 var body = $( body );
 var replaced = body.html().replace(text, <span class="hasStyle"> +text+ </span> ); 
 $( body ).html(replaced);
最佳回答

(1) 你们的一部分是确定价值观。

(2) 请审判

var ccsStyle="font-weight:bold";
var elements = [];
$("*").each(function(){
  var st = $(this).attr("style");
  if(st.indexOf(cssStyle) > -1) elements.push(this);
});

// now elements array holds all you need to replace
问题回答

Use the filter wrap, jQuery。 这是一个简单的例子:

$("*").filter(function(i, elm) {
    return $(elm).css("text-decoration").match(/underline/i);
}).wrap("<span class="highlight" />");

http://jsfiddle.net/joshcomley/6RNQx/

这应当给你一个关于如何处理这一问题的一般想法,而且你可以很容易地将过滤器扩大到你自己的标准。

你们能够取得成功。

$(this).find("span").each(function(index, value){

    var fontstyle = $(this).css( font-style );
    if(fontstyle == "italic")
    {
        //Do it here                 
        alert("it s italic
" + $(this).html());
    }
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签