在我的MVC 3應用程序中,我使用CKeditor編輯富文本。現在我需要能夠使用HTML標籤將文本保存到數據庫。Javascript函數未被解僱?
問題是,當我點擊按鈕'保存'時,沒有任何反應。
警報返回未定義。
查看:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
@Html.DropDownListFor(model=>model.Id, Model.Texts)
<div class="editor-field">
@Html.TextAreaFor((model => model.Text), new { @Id = "editor1" })
@Html.ValidationMessageFor(model => model.Text)
</div>
<script type="text/javascript">
CKEDITOR.replace('editor1');
</script>
<script type="text/javascript">
var editor_data1 = $('editor1').val();
var editor_data = editor_data1.getHtml();
var url = '@Url.Action("EditText", "Admin")';
var data = { commentText: editor_data };
function Save() {
alert(editor_data);
$.post(url, data, function(result) {
});
};
$('#Id').change(function() {
var selectedText = $(this).val();
if (selectedText != null && selectedText != '') {
$.getJSON('@Url.Action("Text","Admin")', { Id: selectedText }, function (text) {
// var textSelect = $('#Text');
// textSelect.empty();
// $("#Text")[0].value = text;
CKEDITOR.instances['editor1'].setData(text);
// $.each(text, function (index, employee) {
// textSelect.append($('<option/>', {
// value: employee.Value,
// text: employee.Text
//// }));
// });
});
}
});
</script>
</fieldset>
<p>
<input type="button" value="Save" onclick="Save()"/>
</p>
}
ttryed的一切,還是一樣...警報返回undefined,而我無法找到任何地方的互聯網,人們從CK編輯 – Timsen 2012-02-11 21:32:15
@Timsen retrive數據上,也許你在你的代碼中有一些其他的錯誤。看看你的javascript調試控制檯。正如你所看到的,在你發佈的這個非常簡單的代碼片段中,我發現了很多問題。你會讓我現在下載CKEDITOR併爲你寫一個完整的例子嗎?我只是準備看電影:-) – 2012-02-11 21:33:53
以及我在javascripting awefull(剛開始學習它)。 #id是dropdownlistitem的ID,所以它確定,該部分正常工作。 – Timsen 2012-02-11 21:38:34