如何隐藏和显示标签控件JavaScript
How to hide and show label control JavaScript?
我有一个项目,我必须为网上购物设置发货地址。对于支付,支付选项是各种信用卡,例如:贝宝,签证等,所以支付选项是一个下拉菜单。
我有两个标签,即"信用卡号码"answers"ccv"。这些最初应该隐藏起来。一旦选择了付款选项(从下拉列表中),这两个标签就会出现。
$(document).ready(function() {
$('.nav-toggle').click(function() {
//get collapse content selector
var collapse_content_selector = $(this).attr('href');
//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function() {
if ($(this).css('display') == 'none') {
//change the button label to be 'Show'
toggle_switch.html('Show');
} else {
//change the button label to be 'Hide'
toggle_switch.html('Hide');
}
});
});
});
.round-border {
border: 1px solid #eee;
border: 1px solid rgba(0, 0, 0, 0.05);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
padding: 10px;
margin-bottom: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<section class="round-border">
<div>
<button href="#collapse1" class="nav-toggle">credit card</button>
</div>
<div id="collapse1" style="display:none">
<label>
Payment Option
<select name="credit">
<option value="paypal">Paypal</option>
<option value="Visa">Visa</option>
<option value="Visa">Master Card</option>
<option value="Discover">Discover</option>
<option value="American Express">American Express</option>
<option value="Alipay">Alipay</option>
</select>
</label>
<br>Card Number:
<input type="text" size="24" maxlength="20" name="cc_number" onBlur="
cc_number_saved = this.value;
this.value = this.value.replace(/[^'d]/g, '');
if(!checkLuhn(this.value)) {
alert('Sorry, this is not a valid number - Please try again!');
this.value = '';
}
" onFocus="
// restore saved string
if(this.value != cc_number_saved) this.value = cc_number_saved;
">
<input type="submit" type="submit" name="submit" value="Ok">
<br>ccv:
<input type="text" name="ccv" required>
<br>
</div>
</section>
</body>
此代码按照您的要求执行。
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
label {
display:none;
}
</style>
<script>
function display() {
ccn.style.display='inherit';
ccv.style.display='inherit';
}
</script>
</head>
<body>
<form>
<select onchange='display();'>
<option selected>Please select...</option>
<option>Visa</option>
<option>MasterCard</option>
<option>Paypal</option>
</select>
<label id='ccn'>Credit Card Number</label>
<label id='ccv'>Credit Card Validation</label>
</form>
</body>
</html>
function display() {
ccn.style.display = 'inherit';
ccv.style.display = 'inherit';
}
label {
display: none;
}
<form>
<select onchange='display();'>
<option selected>Please select...</option>
<option>Visa</option>
<option>MasterCard</option>
<option>Paypal</option>
</select>
<label id='ccn'>Credit Card Number</label>
<label id='ccv'>Credit Card Validation</label>
</form>
label元素的CSS最初不显示标签。当下拉列表更改时,onChange
事件将触发,它将调用display()
函数。然后,通过DOM更改标签的样式,使标签可见。
我不知道脚本规则,但为了符合要求,我修改了代码。
相关文章:
- 在高图表中,每x步只显示标签
- 如何隐藏和显示标签控件JavaScript
- 如何在angular js的ng应用程序中以普通的htm显示标签
- 使用细丝组tablesaw插件时未显示标签
- 用Javascript在具有相同类的按钮上显示标签
- Dijit 按钮显示图标,但不以编程方式显示标签
- 当圆形图像在圆轮中发生变化时,如何在顶部显示标签
- jqPlot - 无法使 x 轴正确显示标签
- 在堆叠条形图上显示标签
- 在酒窝气泡图中的每个气泡内显示标签
- Struts2 显示标签动态链接显示相同的行值
- HTML,显示标签的输入值
- JS sup() 在 html 中显示标签
- 如何在我的WinJS工具栏上显示标签
- d3图表宽度不会在x轴上显示标签
- 如何在鼠标悬停在条形图上时显示标签
- Select2.js-如何防止显示标签
- 我无法在JQChart中显示标签
- 使用 jQuery 验证并尝试在标签无效时突出显示标签
- 将鼠标悬停在圆上时显示标签