ckeditor getData 和 setData 不适用于 masterPage
ckeditor getData and setData is not working with masterPage
您好,我在 asp.net 中使用 ckeditor。在一个简单的网页中,setData 和 getData 函数工作正常,但是当我 运行 另一个页面中的相同代码继承母版页时,我遇到了错误。
代码是:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
$('.active').click(function () {
alert(CKEDITOR.instances['txt'].getData());
})
})
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ckeditor:ckeditorcontrol runat="server" id="txt" name="" width="870"></ckeditor:ckeditorcontrol>
<span style="margin:20px!important;cursor:pointer" class="active">testing</span>
</asp:Content>
错误是:未捕获类型错误:无法读取未定义的 属性 'getData'
系统无法读取 ckeditor 的 ID,因为使用母版页转换控件的客户端 ID,就像在您的示例中一样,没有母版页 ID 是 "txt",使用母版页 ID 就像 "ContentPlaceholderID_txt".
所以你可以为ckeditor使用ClientIDMode="Static"。如下所示:-
<ckeditor:ckeditorcontrol runat="server" id="txt" name="" width="870" ClientIDMode="Static"></ckeditor:ckeditorcontrol>
我想这会解决你的问题。
您好,我在 asp.net 中使用 ckeditor。在一个简单的网页中,setData 和 getData 函数工作正常,但是当我 运行 另一个页面中的相同代码继承母版页时,我遇到了错误。
代码是:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
$('.active').click(function () {
alert(CKEDITOR.instances['txt'].getData());
})
})
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ckeditor:ckeditorcontrol runat="server" id="txt" name="" width="870"></ckeditor:ckeditorcontrol>
<span style="margin:20px!important;cursor:pointer" class="active">testing</span>
</asp:Content>
错误是:未捕获类型错误:无法读取未定义的 属性 'getData'
系统无法读取 ckeditor 的 ID,因为使用母版页转换控件的客户端 ID,就像在您的示例中一样,没有母版页 ID 是 "txt",使用母版页 ID 就像 "ContentPlaceholderID_txt". 所以你可以为ckeditor使用ClientIDMode="Static"。如下所示:-
<ckeditor:ckeditorcontrol runat="server" id="txt" name="" width="870" ClientIDMode="Static"></ckeditor:ckeditorcontrol>
我想这会解决你的问题。