javascript - 更改边距
并在目标 c 中的 wkwebview 套件中
问题描述
我想减少 HTML 字符串中的空间。下面是正在使用的代码
NSString *headerString = @"<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header>";
headerString = [headerString stringByAppendingString:htmlstring];
headerString = [headerString stringByReplacingOccurrencesOfString:@"<br><br/><br/><br><br/><br/>" withString:@"<br><br/>"];
headerString = [headerString stringByReplacingOccurrencesOfString:@"<br><br/><br><br/>" withString:@"<br><br/>"];
[webviewkit loadHTMLString:headerString baseURL:nil];
我也尝试过使用 Javascript,但我不确定我应该传递的 java 脚本到底是什么,它只会给出 1 行间距而不是多行间距:
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[webView evaluateJavaScript:@"document.open();document.close()" completionHandler:^(id _Nullable stringresult, NSError * _Nullable error) {
NSLog(@"result=>%@ error->%@",stringresult,error);
}];
}
但我无法正确删除间距。
<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header><div><span style="font-size: 16px;"><span style="font-size: 16px; font-family: Arial;">Hello and welcome to XYZ session! </span><br><br/><span style="font-family: Arial;">Over the next three Hello world. Spacing takes alot of spaces over here due to span , br and div tags.</span><br><br/><span style="font-family: Arial;">Thank you again for agreeing to participate and helping the discussion....</span><br><br/><span style="font-family: Arial;">Over here,</span><br><br/></span></div><br/><ul><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">I will be posting questions over here in stack overflow </span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Throughout the day I will read everyone's responses and sometimes respond with my own follow-up questions. </span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Please be i request to provide the code in objective c</span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span><br><br/> </span></li><br/> <li><span style="font-size: 16px; font-family: Arial;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span></li><br/></ul>
解决方案
我想你可能对<br>
标签有点困惑。 <br>
或者<br />
是自闭合/无效元素/空标签:
https://www.w3schools.com/html/html_elements.asp(在空的 html 部分下) http://xahlee.info/js/html5_non-closing_tag.html
<br>
是一个没有结束标签的空元素(<br>
标签定义了一个换行符):
因此,当您插入字幕时,<br><br />
实际上是在两个换行符中插入字幕。根据您的描述,听起来好像您只想要一个换行符,因此您需要删除其中一个。
推荐阅读
- javascript - 如何在 Kendo UI jQuery 中获取下拉列表的选定文本?
- json - 如何从文本中获取摘录
- graphql - 在一个请求中接受多级对象数组的 GraphQL 突变
- jenkins - 我在哪里可以找到 Jenkins 服务器上的“托管文件”物理文件?
- flask - Dash-Plotly null 不是对象(评估“figure.data”)
- python - 如何修复 .index() 方法返回错误值?
- ios - 钥匙串没有在 iOS 上触发
- google-analytics - 电子商务数据未从谷歌标签管理器传递到分析
- r - 如何在水平条形图中的条形右侧添加计数标签?
- nativescript - Nativescript 安装程序不会安装在 4.1.2 以上