如何向Wordpress wp_editor textarea字段添加自定义属性?
在官方文档中,没有办法做到这一点。我需要将客户端验证属性(data-bvalidator =“required”)添加到由WordPress的 wp_editor 方法生成的文本区域。
有什么建议吗?
答案 0 :(得分:2)
我认为在wp_editor()
因此,您需要使用text-area
JQuery
字段中添加自定义属性
首先将额外的类添加到编辑器text-area
$settings = array(
......
'editor_class' => 'customclass_for_addattr',
......
);
wp_editor( $content, $editor_id, $settings );
在wp_editor()函数之后添加以下jQuery代码。它使用jQuery text-area
方法
atrr
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".customclass_for_addattr").attr('data-bvalidator','required');
});
</script>