Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        上个月关闭。
                                                                                            
                
        

  MMM先生和SSSS夫人很诚实。他们有自己的车。


在这里,我想将第一句话改为粗体,


  我们有一位伟大的领袖F.Rah。他是一个有才华的男孩。


在这里,我想将第一句话改为粗体,


  我们有一位伟大的领袖F.Rah。


在这里,我想将句子更改为粗体。

最佳答案

var a = $('.last_wfp').text();
var b = a.slice(0, a.indexOf('. '));
var c = a.slice(a.indexOf('. '), a.length);

$('.last_wfp').html('<span class="last_bold">' + b + '</span>' + c);

var a = $('.last_wfp1').text();
var b = a.slice(0, a.indexOf('. '));
var c = a.slice(a.indexOf('. '), a.length);


$('.last_wfp1').html('<span class="last_bold">' + b + '</span>' + c);


var a = $('.last_wfp2').text();
var b = a.slice(0, a.indexOf('. '));
var c = a.slice(a.indexOf('. '), a.length);


$('.last_wfp2').html('<span class="last_bold">' + b + '</span>' + c);

.last_bold{
    font-weight:bold;
    padding-top:2em;
    display:inline-block;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p class="last_wfp">This is the first sentence that I want bold. This is the second sentence that I don't want that treatment. This text is lost! And then there was more.  And another sentence...</p>
<p class="last_wfp1">This is the second sentence that I want bold . This is the second sentence that I don't want that treatment. This text is lost! And then there was more.  And another sentence...</p>
<p class="last_wfp2">This is the third sentence that I want bold.</p>

关于javascript - 我需要使用javascript和css将段落中的第一句话更改为仅粗体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59210682/

10-11 06:33