![](/img/trans.png)
[英]How can I cut a javascript array in half but to the nearest closing </p> or </h1> tag?
[英]How to format a line in current cursor to <h1> or <p> tag by javascript execCommand?
我正在學習格式化可編輯的html文本並在UIWebView中顯示
// html文件
<html>
<body>
<div id="content" contenteditable="true" style="font-family: Helvetica">
</div>
</body>
</html>
//加載到WebView
[self.webView loadHTMLString:[[NSString alloc] initWithData:
[[NSFileHandle fileHandleForReadingAtPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]] readDataToEndOfFile] encoding:NSUTF8StringEncoding]
baseURL:[NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]]
];
某些標記,例如b或i可以通過以下方式插入或刪除以選擇當前文本
-(IBAction)bold:(UIButton *)sender {
[self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('bold')"];
}
-(IBAction)italic:(UIButton *)sender {
[self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('italic')"];
}
我搜索了很多,但仍然卡住了。 請給個建議!
我從這份文件中得到答案
[self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('formatBlock', false, 'p')"];
[self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('formatBlock', false, 'h1')"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.