前一陣開(kāi)發(fā)中使用ZSSRichTextEditor做編寫文章功能,其中使用加粗等樣式,遇到的加粗之后不能還原的問(wèn)題,經(jīng)過(guò)一番查找無(wú)果,自己用了一種投機(jī)取巧的方法,最后也算是解決了這個(gè)問(wèn)題,在此記錄一下.
zss_editor.setBold =function() {
? ? if(document.queryCommandState('bold')) {
? ? ? ? document.execCommand('bold',false,'div');
? ? ? ? document.execCommand('insertHTML',false,'‌');
? ? }else{
? ? ? ? document.execCommand('bold',false,null);
? ? }
? ? zss_editor.enabledEditingItems();
}
這個(gè)方法加粗后點(diǎn)擊兩次才會(huì)還原,這個(gè)是完全不能接受的,具體原因還不可知因?yàn)閷?duì)網(wǎng)頁(yè)這塊的知識(shí)還有所欠缺,但是發(fā)現(xiàn)是系統(tǒng)的鍵盤才會(huì)出現(xiàn)這個(gè)問(wèn)題,第三方的鍵盤沒(méi)有問(wèn)題,一開(kāi)始想著系統(tǒng)鍵盤和第三方鍵盤區(qū)分來(lái)做,但還是以失敗告終。
? ? NSString*html =@"\n<b></b>";
? ? [_editor setHTML:html];
最后加了這兩行代碼之后也算是解決了問(wèn)題,希望遇到的同學(xué)可以有所幫助,也是自己再次記錄一下。其他的例如抖動(dòng)的問(wèn)題都可以搜的到,我就不再次記錄了,遇到其他的問(wèn)題可以去其他文章查看
最近又發(fā)現(xiàn)了一種方法就是自己加入html直接加標(biāo)簽
zss_editor.bold =function() {
? ? document.execCommand('insertHTML',false,'<b>‌</b>');
? ? zss_editor.enabledEditingItems();
}
zss_editor.thin =function() {
? ? document.execCommand('insertHTML',false,'‌');
? ? zss_editor.enabledEditingItems();
}