Validation 引导节点验证插件和ifram
我在表单上使用bootstrap-wysihtml5编辑器创建iframe元素Validation 引导节点验证插件和ifram,validation,twitter-bootstrap,iframe,Validation,Twitter Bootstrap,Iframe,我在表单上使用bootstrap-wysihtml5编辑器创建iframe元素 <iframe class="wysihtml5-sandbox" width="0" height="0" frameborder="0" security="restricted" allowtransparency="true" marginwidth="0" marginheight="0" name="for_nod" src="#" style="display: inline-block; bac
<iframe class="wysihtml5-sandbox" width="0" height="0" frameborder="0" security="restricted" allowtransparency="true" marginwidth="0" marginheight="0" name="for_nod" src="#" style="display: inline-block; background-color: rgb(255, 255, 255); border-collapse: separate; border-color: rgb(204, 204, 204); border-style: solid; border-width: 1px; clear: none; float: none; margin: 0px 0px 10px; outline: 0px none rgb(0, 0, 0); outline-offset: 0px; padding: 4px 6px; position: static; top: auto; left: auto; right: auto; bottom: auto; z-index: auto; vertical-align: middle; text-align: start; -moz-box-sizing: content-box; box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.075) inset; border-radius: 4px 4px 4px 4px; width: 750px; height: 300px;">
<html>
<head>
<meta charset="UTF-8">
<link href="/js/plug-ins/bootstrap-wysihtml5/rtl/rtl-editor.css" rel="stylesheet">
<style type="text/css">
</head>
<body class="wysihtml5-editor" contenteditable="true" spellcheck="true" style="background-color: rgb(255, 255, 255); color: rgb(85, 85, 85); cursor: text; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; line-height: 20px; letter-spacing: normal; text-align: start; text-decoration: none; text-indent: 0px; text-rendering: optimizelegibility; word-break: normal; word-wrap: break-word; word-spacing: 0px;">
simple text
<br>
</body>
</html>
</iframe>
简单文本
我需要使用Nod验证插件验证iframe中的body元素是否为空
问题是Nod验证插件接受jquery选择器文本来设置元素而不是对象的验证规则-我可以使用$(“iframe”).content().find(“body”)获取iframe对象,但验证逻辑不起作用
我尝试将submit button onclick事件处理程序设置为手动处理iframe的验证,问题是如果Nod使用的规则通过,那么如果自定义验证函数返回true或false值,则该函数将无效
不管怎样,你想回避这个问题吗 通过创建非显示的textarea元素,然后使用自定义事件功能监听iframe body的更改事件,并将隐藏的textarea内容最小化,我的问题已经得到解决。 节点规则已应用于隐藏的文本区域 我不确定这是否是一个完美的解决方案,但我别无选择:)目前 自定义内容更改事件代码
/*
* custom-change-event
*
* This custom event is used for those elements
* that has no support for default change event
* like : body , div ,span, ....
*
*
*/
var interval;
jQuery.fn.contentchange = function (fn) {
return this.on('contentchange', fn);
};
jQuery.event.special.contentchange = {
setup: function (data, namespaces, eventHandle) {
var self = this,
$this = $(this),
$originalContent = $this.text();
interval = setInterval(function () {
if ($originalContent != $this.text()) {
$originalContent = $this.text();
jQuery.event.special.contentchange.handler.call(self);
}
}, 500);
},
teardown: function (namespaces) {
clearInterval(interval);
},
handler: function (event) {
$(this).trigger('contentchange');
}
};