1.當(dāng)點(diǎn)擊“長(zhǎng)期有效”時(shí),打印出“長(zhǎng)期有效”。2.當(dāng)點(diǎn)擊自定義后,顯示時(shí)間彈出框并選擇時(shí)間后,打印出當(dāng)前日期。(這邊要判斷是否選擇了日期,沒有選擇日期的話要alert選擇時(shí)間)HTML代碼<div class="col-sm-10">
<input type="radio" name="inlineRadioOptions1" id="inlineRadio1" value="option1" class="dateChoose" value="
0">
<label for="inlineRadio1">長(zhǎng)期有效</label>
<input type="radio" name="inlineRadioOptions1" id="inlineRadio2" value="option2" class="dateChoose others" value=
"1">
<label for="inlineRadio2">自定義</label>
<input type="date" name="inlineDateChoose" class="form-control dateJump" id="datetimeInput" value="" placeholder="" style="width: 165px">
<button id="btn" class="btn">點(diǎn)我</button>
</div>顯示/隱藏效果代碼<style>
.others ~ input[type='date'] {
display:none;
}
.others:checked ~ input[type='date'] {
display:inline;
}
#date:before {
content:"before";
}
#date::before {
content:"before";
}
</style>顯示/隱藏JS效果代碼$(function(){
$(".dateChoose").click(function(){
$(this).siblings().attr("checked",false);
$(this).attr("checked",true);
if($(this).attr("class").indexOf('others')>=0){
$(this).siblings('.dateJump').show();
}
else{
$(".others").siblings('.dateJump').hide();
}
});
})JS判斷代碼?。。?!var v1 = document.getElementById('inlineRadio1');
var v2 = document.getElementById('inlineRadio2');
if(v1.value == '0'){
times = "長(zhǎng)期有效";
console.log(times);
return times;
}
else {
if(v2.value == '1'){
times = $(".dateJump");
console.log(times);
return times;
}
else {
alert("請(qǐng)選擇截止時(shí)間");
return times;
}
}
$('.btn').click(function () {
console.log(times.val());
})//打印出times的值為時(shí)間或者“長(zhǎng)期有效”效果圖選擇長(zhǎng)期有效時(shí)選擇自定義并選擇時(shí)間各位大佬,主要是判斷這邊的代碼不知道怎么寫,我是設(shè)置了他value的值,從判斷value的值來(lái)判斷點(diǎn)選了那個(gè)選項(xiàng)?。?!最終打印出的結(jié)果times的值為時(shí)間或者“長(zhǎng)期有效”?。。?
判斷?。?!如何在JS里面通過value值判斷當(dāng)前選擇的按鈕,并打印出來(lái)
慕斯王
2019-04-18 18:15:49