Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将当前光标中的行格式化为<;h1>;或<;p>;通过javascript execCommand标记?_Javascript_Ios_Uiwebview - Fatal编程技术网

如何将当前光标中的行格式化为<;h1>;或<;p>;通过javascript execCommand标记?

如何将当前光标中的行格式化为<;h1>;或<;p>;通过javascript execCommand标记?,javascript,ios,uiwebview,Javascript,Ios,Uiwebview,我正在学习格式化可编辑的html文本并在UIWebView中显示 //html文件 <html> <body> <div id="content" contenteditable="true" style="font-family: Helvetica"> </div> </body> </html> 一些标签,如b或i可以通过以下方式插入或删除到当前选择文本中: -(IBAction)bold:(UIB

我正在学习格式化可编辑的html文本并在UIWebView中显示

//html文件

<html>
<body>
    <div id="content" contenteditable="true" style="font-family: Helvetica">

    </div>
</body>
</html>
一些标签,如bi可以通过以下方式插入或删除到当前选择文本中:

-(IBAction)bold:(UIButton *)sender {
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('bold')"];
}

-(IBAction)italic:(UIButton *)sender {
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('italic')"];
}
我想找到一个命令,将当前行文本格式化为h1h2ppre标记。 我找了很多,但还是卡住了。请给我一个建议

我的答案来自


有趣的问题,但必须使用
execCommand
?谢谢!我需要从iOS中的一个按钮格式化它
-(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')"];