2016-08-01 50 views
0

我想要有可以有<button><a></a></button>的小工具。不幸的是,CKE刪除了<a></a>。如何克服這一點?CKEditor不允許在小工具中嵌套<a>元素

這是代碼:

CKEDITOR.plugins.add('interButton', { 
    requires: 'widget', 
    icons: 'interButton', 
    init: function(editor) { 

     editor.widgets.add('interButton', { 
      button: 'Add Button', 

      template: 
       '<button><a></a></button>', 

      allowedContent: 
       'button[*]{*}(*); a[*]{*}(*)', 

      upcast: function(element) { 
       return element.name == 'button'; 
      } 
     }); 

    } 
}); 
+1

你真的想克服有效的HTML嗎?參考:https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element – Wolfgang

+0

你能更具體嗎? – zie1ony

+1

將一個錨標籤放在按鈕中對HTML無效 – Wolfgang

回答

1

你可以把某些元素的protectedSource和CKE將服從。

例如:

config.protectedSource.push(/<button[^>]*><a[^>]*><\/a><\/button>/g); 

我沒有測試以上,但它應該工作。