html根据输入判断隐藏或显示,根据搜索输入隐藏/显示div

我已经制定了一些javascript来使用我的搜索栏来过滤/隐藏与搜索输入不匹配的内容。我说它的工作率约为95%我会说但是我有一个问题要解决。

所以我的页面显示家具组及其包含的家具。组名称/编号和描述作为标题div存在,下面有一个用实际家具创建的表格。只要我在打字沙发'或者'主席'这将在表格行中。但是,如果我键入家具组的名称,它只显示名称/编号/描述和图像,但隐藏表格。组名称/描述在此块中:

@foreach ($orderFormData->pgroups as $pgroup)

{{ $pgroup->group_name

}} - {{ $pgroup->group_code }}

{!!

html_entity_decode($pgroup->group_desc) !!}

所以,我需要尝试稍微重构一下以添加功能,这样如果我的输入与组名称或描述匹配,它仍会显示该div的整个表格。

我的想法是添加类似的东西

if($('.group-container').children('tr:visible').length == 0) {

$('.group-container').hide();

} else {

$('.group-container').show();

}

在我的第一行html下面,在foreach循环下面。但我不知道这是不是正确的想法,也不知道如何正确地使用它。

HTML:

@foreach ($orderFormData->pgroups as $pgroup)

{{ $pgroup->group_name }} - {{ $pgroup->group_code }}

{!! html_entity_decode($pgroup->group_desc) !!}

@foreach ($pgroup->image_names as $image_name)

%7B%7B%20substr(%24image_name,%200,%20strpos(%24image_name,%20','))%20%7D%7D {{ substr($image_name, strpos( $image_name, ',') + 1) }}

@endforeach

FrameDescriptionCover/ColorCover/ColorQuantityPrice

@foreach ($pgroup->pskus as $psku)

{{ $psku->frame_fmt }}{!! html_entity_decode($psku->frame_desc) !!}{{ $psku->cover1_code }}/{{ $psku->color1_code }} {{ $psku->color1_desc }}{{ $psku->cover2_code }}/{{ $psku->color2_code }} {{ $psku->color2_desc }}

${{ $psku->price }}

@endforeach

@endforeach

JS:

$(document).ready(function(){

$("#srch-term").keyup(function(){

// Retrieve the input field text and reset the count to zero

var filter = $(this).val(), count = 0;

// Loop through the main container as well as the table body and row that contains the match

$(".group-container, tbody tr").each(function(){

// If the list item does not contain the text phrase fade it out

if ($(this).text().search(new RegExp(filter, "i")) < 0) {

$(this).fadeOut();

// Show the list item if the phrase matches and increase the count by 1

} else {

$(this).show();

count++;

}

});

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来解答你的问题。 首先,你需要使用 ant-design-vue 组件库中的 Input 和 Tag 组件。在 Input 组件中监听回车或离开输入框事件,将输入的内容添加到一个数组中。然后,在 Tag 组件中使用 v-for 指令循环渲染数组中的标签。 下面是一个简单的示例代码,可以帮助你实现上述功能: ```html <template> <div> <div :class="{ 'hidden': tags.length < 1 }"> <div v-for="(tag, index) in tags" :key="index" class="tag"> {{ tag }} </div> </div> <a-input v-model="inputValue" @pressEnter="handleInput" @blur="handleInput" :disabled="tags.length >= 10" :placeholder="tags.length >= 10 ? '标签已达到上限' : '请输入标签'" /> </div> </template> <script> export default { data() { return { tags: [], inputValue: '' }; }, methods: { handleInput() { if (this.inputValue.trim() && this.tags.length < 10) { this.tags.push(this.inputValue.trim()); this.inputValue = ''; } } } }; </script> <style> .hidden { display: none; } .tag { display: inline-block; margin-right: 8px; margin-bottom: 8px; padding: 4px 8px; border-radius: 4px; background-color: #f0f0f0; } </style> ``` 在上面的代码中,通过 v-bind:class 指令动态绑定样式,根据 tags 数组长度是否大于等于 1 来判断是否隐藏左边的盒子。在 handleInput 方法中,通过 trim 方法去除输入内容的前后空格,并判断 tags 数组长度是否小于 10,如果满足条件,则将输入内容添加到 tags 数组中,并清空输入框内容。 希望这个示例可以帮助你实现功能。如果还有任何问题,欢迎随时提出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值