【发布时间】:2017-05-30 18:09:05
【问题描述】:
我有这个函数/脚本可以将复选框转换为单选按钮(在类别元框中),但我需要稍微扩展一下功能,但我不确定如何去做。
脚本:
function convert_root_cats_to_radio() {
global $post_type;
?>
<script type="text/javascript">
jQuery("#categorychecklist>li>input").each(function(){
this.disabled = "disabled";
});
jQuery("#categorychecklist>li>ul>li>input").each(function(){
this.disabled = "disabled";
});
jQuery("#categorychecklist>li>label input").each(function(){
this.type = 'radio';
});
jQuery("#categorychecklist>li>ul>li>label input").each(function(){
this.type = 'radio';
});
// Hide the 'most used' tab
jQuery("#category-tabs li:odd").hide();
</script> <?php
}
add_action( 'admin_footer-post.php', 'convert_root_cats_to_radio' );
add_action( 'admin_footer-post-new.php', 'convert_root_cats_to_radio' );
现在需要做的是:防止用户选择父类别。
例如,在下面显示的图像中,您应该能够选择除 Bandicoot 之外的任何内容,因为 Bandicoot 是父级(它有子级)。哦,并且允许选择 Bandicoot 的子项。
所以规则应该是:如果你是父母,你不能被选中,但你的孩子可以。
【问题讨论】:
-
你能分享这部分渲染的 html 吗?将有助于查看遍历。
标签: javascript jquery wordpress function categories