我打算在 Woocommerce 中使用 jQuery 來根據選擇框值隱藏我的帳單欄位中的表單欄位,jQuery 確實隱藏了元素和標簽:我的代碼是:
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.
uj5u.com熱心網友回復:
可能會keyup根據您的輸入嘗試事件,我已經設法解決了您的問題。
演示
HTML
<label for="#billing_condition">Label</label>
<input type="text" id="billing_condition"/>
爪哇腳本
$(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();
}
});
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366030.html
下一篇:如何在Json中斷線
