如何解决Yii 中的自定义类别字段
我正在修改一个在 Yii 框架中制作的分类应用程序。该应用程序已经包含基于类别的字段,现在我想用相同的代码触发另一个输入字段。我尝试添加 $('.price-type').show();在JS中。但这没有帮助。
JS文件
$(document).on('click','#modal-category .modal-footer #success-selection',function (e) {
e.preventDefault();
$('#choose-class').text($(this).data('selectedText'));
$('input#listing-category_id').val($(this).data('selectedId'));
$.post($('#category-fields').data('url'),{
category_id:$(this).data('selectedId'),listing_id:$('#post-form').data('listing'),},function (json) {
if(json.html) {
$('.category-fields').show();
$('.price-types').show();
$('#category-fields').html(json.html);
$('select').select2({
width: '100%',language: site.language,dir: site.dir,});
}else{
$('.category-fields').hide();
}
},'json');
});
表单.php
<div class="row price-types" id="price-types" style="display: none">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
<?= $form->field($ad,'pricetype',[
'template' => '{input} {error}',])->textInput(['placeholder' => t('app','Price Type'),'class' => 'form-control'])->label(false); ?>
</div>
</div>
<div class="row category-fields" id="category-fields" data-url="<?= url(['/listing/get-category-fields']); ?>" style="display: none">
</div>
解决方法
请尝试使用
$(document). ready(function() {
$('.price-types').hide();
});
而不是为 div 使用 style="display: none" 然后你可以取消隐藏元素:
$('.price-types').show();
任何想要的活动。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。