javascript - I need to change the first sentence only bold from paragraph using javascript and css
问题描述
Mr. MMM and Mrs. sss they are honest. They have their own car.
Here I want to change the first sentence to bold,
We have a great leader F.Rah. He is a talented boy.
Here I want to change the first sentence to bold,
We have a great leader F.Rah.
Here I want to change the sentence to bold.
解决方案
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>
推荐阅读
- php - laravel mix sass 不会改变
- python - Python - 根据这些值拟合 GEV 分布
- r - R imager isoblur:它如何计算边界?是否可以根据其公式构建神经网络?
- android - Pinterest sdk 回调类错误:无法访问 com.android.volley.Response 的响应类文件未找到
- java - 在 Spring 测试中连接 bean 期间不存在获取包
- vue.js - 动态解析 Vue 组件名称
- reactjs - 如何使用 Jest 监视类属性箭头函数
- javascript - POST auth-service.ts ionic 3 应用程序上的语法错误
- c# - 下载文件或通过 web api 方法发送 json
- php - PHPExcel setAutoSize 仅基于第 1 行