首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >jQuery不隐藏标签和元素

jQuery不隐藏标签和元素
EN

Stack Overflow用户
提问于 2021-11-25 08:17:00
回答 1查看 87关注 0票数 1

我正在绑定使用Woocommerce中的jQuery来根据复选框值隐藏我的账单字段中的表单字段,jQuery确实隐藏了元素或标签:我的代码是:

代码语言:javascript
运行
复制
jQuery(document).ready(function(){
    // Your code in here
  jQuery(document).on('input','billing_condition', function() {
 
      mySecFunc();
})
function mySecFunc() {
    // your function code
if(jQuery('#billing_condition').val() == 'house'){
    console.log('before');
    
    jQuery('#billing_complex_name').hide();
    jQuery('label[for="billing_complex_name"]').hide();
    
    jQuery('#billing_complex_address').hide();
    jQuery('label[for="billing_complex_address"]').hide();
    
    jQuery('#billing_complex_address_inside').hide();
    jQuery('label[for="billing_complex_address_inside]').hide();

    console.log('after');
    
}else{
    console.log('before');
    
    jQuery('label[for="billing_address_1"]').hide();
    jQuery('#billing_address_1').hide();
    
    jQuery('label[for="billing_complex_name"]').show();
    jQuery('#billing_complex_complex_name').show();
    jQuery('#billing_complex_address').show();
    jQuery('label[for="billing_complex_address"]').show();
    
    jQuery('#billing_complex_address_inside').show();
    jQuery('label[for="billing_complex_address_inside"]').show();

    console.log('after');
    
}
}})```

The elements were going prior however are not at current nor are the labels.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-25 09:51:15

可能在您的输入上尝试了keyup事件,我已经设法解决了您的问题。演示

HTML

代码语言:javascript
运行
复制
<label for="#billing_condition">Label</label>
<input type="text" id="billing_condition"/>

JAVASCRIPT

代码语言:javascript
运行
复制
$(document).ready(function() {
  var input = $("#billing_condition");
  input.keyup(function() {
    if (input.val() == "abc") {
      $('label[for="#billing_condition"]').hide();
    } else {
        $('label[for="#billing_condition"]').show();
    }
  });
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70107784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档