gpt4 book ai didi

javascript - 无法在 asp mvc 中验证 TinyMCE

转载 作者:搜寻专家 更新时间:2023-11-01 04:26:42 24 4
gpt4 key购买 nike

我有一个使用非侵入式验证的表单。最近我将文本区域更改为使用 tiny mce,但现在验证不起作用。
我尝试使用 here 中的解决方案但什么也没发生。

$('#form input[type=submit]').click(function () {

从不执行。 这是我的:

@using (Html.BeginForm("Create", "UserAd", FormMethod.Post))
{
...
@Html.TextAreaFor(x => x.Description, new { id = "description" })
...
<input type="submit" value="Create"/>
...

这是JS代码:

$(document).ready(function () {

tinyMCE.init({
mode: "textareas",
theme: "advanced",
skin: "o2k7",
height: "250",
plugins: "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",


theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_buttons4: "",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_resizing: false
});

function toggleEditor(id) {
if (!tinyMCE.get(id)) {
tinyMCE.execCommand('mceAddControl', false, id);
}
else {
tinyMCE.execCommand('mceRemoveControl', false, id);
}
}


// new
$(function () {
var tinymce = $('#Description');

tinymce.tinymce({
setup: function (e) {
e.onInit.add(function () {
tinymce.css({
position: 'absolute',
height: 0,
width: 0,
top: -100
}).show();
});
}
});

$('#form input[type=submit]').click(function () {
alert('ss');
tinyMCE.triggerSave();
});
});
// makes form field highlighting work with bootstrap's css
$.validator.setDefaults({
highlight: function (element, errorClass, validClass) {
$(element).closest('.control-group').addClass('error');
},
unhighlight: function (element, errorClass, validClass) {
$(element).closest('.control-group').removeClass('error');
}

});
$(function () {
// makes form field highlighting work with bootstrap's css on post backs
$('.input-validation-error').each(function (i, element) {
$(element).closest('.control-group').not('.error').addClass('error');
});
});

最佳答案

您在选择器中指定了一个 ID“#form”。尝试从您的选择器中删除 #。

例如,

$('form input[type=submit]').click(function () {
alert('ss');
tinyMCE.triggerSave();
});

此外,如果我没看错代码,tinyMCE 是一个动态元素。您可能希望将点击事件与 on 函数绑定(bind)。

例如,

$("body").on("click","#yourFormID", function(e){
your click stuff here
}

关于javascript - 无法在 asp mvc 中验证 TinyMCE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11601666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com