我使用 CKEDITOR 4.6
我将此代码(Html、JavaScript)设置为 CKEDITOR 的源
<html>
<head>
<title></title>
</head>
<body dir="rtl">
<p>Click the button to display an alert box:</p>
<p><button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
alert("I am an alert box!");
}
</script>
</p>
</body>
</html>
如何在 CKEDITOR 中运行 javascript?
我也设置了这个配置但还是不行
CKEDITOR.editorConfig = function( config ) {
config.allowedContent = {
script: true,
allowedContent :true,
$1: {
// This will set the default set of elements
elements: CKEDITOR.dtd,
attributes: true,
styles: true,
classes: true
}
};
};
最佳答案
你的代码有一些问题:
1:你不应该放 <script>
在 <p>
中标记元素。
2: 大多数时候,你需要在页面完全加载后执行你的 JS,所以将它放在页眉中并不能解决问题,在你的所有内容加载完毕后放置。
有时,除非您使用本地主机,否则 javascript 不会运行,尝试使用 wamp/xamp 等。如果这不起作用
<html>
<head>
<title></title>
</head>
<body dir="rtl">
<p>Click the button to display an alert box:</p>
<p><button onclick="myFunction()">Try it</button></p>
<script>
function myFunction() {
alert("I am an alert box!");
}
</script>
</body>
</html>
关于javascript - 将 javascript 插入到 ckeditor 的正文中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40780285/