问题描述
我正在使用 asp.net mvc 来显示一个 .html 文档,我知道它包含什么.
我的控制器中有这个方法:
public ActionResult GetHtmlPage(字符串路径){return new FilePathResult(path, "text/html");}我有这个简单的视图:
<代码>@{ViewBag.Title = "管理文档";}<h2>管理文档</h2>@Html.Action("GetHtmlPage", "myController", new { path = Model.documentPath })文档显示没有问题.但我想突出显示我知道它存在于文档某处的特定句子.
我的意思是,我正在尝试实现一个 JavaScript 代码,也许是为了找到我想在文档中突出显示的特定句子并突出显示它!我在 JavaScript 中阅读了有关 window.find() 的信息,但我的 asp.net 解决方案似乎无法识别它.
我正在使用 VS2015 企业版
您可以使用 jQuery 用一些标签包装文本并应用您可能需要的任何自定义样式.假设您有以下标记:
这是一些具体的句子</div>而你想要这样结束:
这是<strong>一些具体的</strong>句子</div>您可以尝试使用 :contains 选择器来定位文本的所需部分,然后用一些标签将其包装起来:
$("div:contains('some specific')").html(function(_, html) {return html.replace(/(some specific)/g, "<strong>$1</strong>");});
这里有一个 示例小提琴.
I'm using asp.net mvc to display a .html document that I know exactly what it contains.
I have this method in my controller:
public ActionResult GetHtmlPage(string path)
{
return new FilePathResult(path, "text/html");
}
and I have this Simple view:
@{
ViewBag.Title = "ManageDocument";
}
<h2>ManageDocument</h2>
@Html.Action("GetHtmlPage", "myController", new { path = Model.documentPath })
The document is displayed with no problems. But i want to Highlight a specific sentence that I know it exists somewhere in the document.
What I mean is, I'm trying to implement a JavaScript code maybe to find that specific sentence i want to highlight in the document and highlight it!
I read about window.find() in JavaScript but my asp.net solution doesn't seem to recognize it.
I'm using VS2015 Enterprise
解决方案 You could use jQuery to wrap the text with some tags and apply whatever custom styles you might need. Let's suppose that you have the following markup:
<div>
This is some specific sentence
</div>
and you want to end up with this:
<div>
This is <strong>some specific</strong> sentence
</div>
You could try the :contains selector to locate the desired portion of the text and then wrap it with some tags:
$("div:contains('some specific')").html(function(_, html) {
return html.replace(/(some specific)/g, "<strong>$1</strong>");
});
And here's a sample fiddle.
这篇关于在浏览器中显示的html页面中找到一个句子并突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End
相关推荐
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22
前端开发问题
182
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14
前端开发问题
156
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24
前端开发问题
271
layui中表单会自动刷新的问题,因为用到layui的表单,遇到了刷新的问题所以记录一下: script layui.use(['jquery','form','layer'], function(){ var $ = layui.jquery, layer=layui.layer, form = layui.form; form.on('submit(tijiao)', function(data){ a...
2024-10-23
前端开发问题
262
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18
前端开发问题
301
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18
前端开发问题
125
热门文章
1错误 [ERR_REQUIRE_ESM]:不支持 ES 模块的 require()
2vue中yarn install报错:info There appears to be trouble with you
3为什么 Chrome(在 Electron 内部)会突然重定向到 chrome-error://chromewebdat
4“aria-hidden 元素不包含可聚焦元素"显示模态时的问题
5使用选择器在 CSS 中选择元素的前一个兄弟
6js报错:Uncaught SyntaxError: Unexpected string
7layui怎么刷新当前页面?
8将模式设置为“no-cors"时使用 fetch 访问 API 时出错
热门精品源码
最新VIP资源
1多功能实用站长工具箱html功能模板
2多风格简历在线生成程序网页模板
3论文相似度查询系统源码
4响应式旅游景点宣传推广页面模板
5在线起名宣传推广网站源码
6酷黑微信小程序网站开发宣传页模板
7房产销售交易中介网站模板
8小学作业自动生成程序




大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)