【发布时间】:2015-01-08 22:32:23
【问题描述】:
在 wordpress 中,我为帖子格式创建了一些元框,因此当用户单击一个单选按钮或它已经选中元框显示时。
这是我尝试了一些 jquery 的代码,但我不擅长 jquery
HTML:
<div id="post-formats-select">
<input type="radio" id="post-format-0" class="post-format" value="0" name="post_format" />
<label class="post-format-standard">Standard</label>
<input type="radio" id="post-format-chat" class="post-format" value="chat" name="post_format" />
<label class="post-format-chat">Chat</label>
<input type="radio" id="post-format-gallery" class="post-format" value="gallery" name="post_format" checked="checked" />
<label class="post-format-gallery">Gallery</label>
<input type="radio" id="post-format-video" class="post-format" value="video" name="post_format" />
<label class="post-format-video">Video</label>
</div>
<div class="meta-box-sortables">
<div id="inpost_chat_box" class="postbox">
Chat Box
</div>
<div id="inpost_gallery_box" class="postbox">
Gallery Box
</div>
<div id="inpost_video_box" class="postbox">
Video Box
</div>
</div>
JQuery:
$('#inpost_chat_box, #inpost_gallery_box, #inpost_video_box').hide();
var formats = $('#post-formats-select input');
formats.on('change', function(){
if( $(this).is(':checked').val() == 'gallery' ) {
$('#inpost_gallery_box').show();
}
});
【问题讨论】:
-
这就是你想要的jsfiddle.net/Ac9c4/141
-
你能把你的代码放在一个小提琴里吗?