gpt4 book ai didi

javascript - 单选按钮下拉弹窗费用清零

转载 作者:行者123 更新时间:2023-11-30 17:13:22 26 4
gpt4 key购买 nike

我有两个单选按钮。当您单击第一个单选按钮(是)时,它有一个下拉菜单,可以打开一个弹出窗口并允许您添加一个盘子。如果用户接受了一个盘子,那么用户就无法改变主意并点击否以取消费用..

用户如何更改车牌和费用变化很好,但我坚持的部分是,如果用户决定他们不想要车牌并且他们单击单选按钮(否),它不会取消费用。 .

我已将其设置为清除下拉选择,但这不包括费用部分。有人可以帮忙吗?

我还添加了该复选框,因为我不希望它仅从下拉选项中完全清除所有费用。

如果有人有任何建议或建议,我们将不胜感激!

http://jsfiddle.net/e1ewx5jv/

var specialFee = 0;

$(function(){ //added by me
$('#IRF').click(function(){
calculateTotal();
});
});


function initialRegFee()
{
var initialFee=0;
var theForm = document.forms["form"];
var iRF = document.getElementById('IRF');
if(iRF.checked==true)
{
initialFee=225;
}
return initialFee;
}

function calculateTotal()
{

var titleFees = initialRegFee();
titleFees += specialFee;


var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Estimated Transfer Fees $"+titleFees;

}

function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}

$(function() {
$('#SPECIAL').on('change', function() {
if ($('option:selected', this).is('[data-img]')) {

$('#modal_special').find('.modal-title').html($('option:selected', this).data('name'));
$('#modal_special').find('.modal-body').html('')
.append('<img alt="coming soon" src="' + $('option:selected', this).data('img') + '"/><br/><br/> Would you like to add this license plate for: $' + $('option:selected', this).data('price') + ' ?')
.end().modal('show');
}
});

$('.accept').on('click',function() {
specialFee = $('option:selected').data('price');
calculateTotal();
$('#modal_special').modal('hide');
});
});

function showhideSPForm(SP) {
if (SP == "Yes") {
document.getElementById("div8").style.display = 'block';
document.getElementById("div9").style.display = 'none';
} else if (SP == "No") {
document.getElementById("div9").style.display = 'block';
document.getElementById("div8").style.display = 'none';
document.getElementById("SPECIAL").selectedIndex = 0;
}
calculateTotal();

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<form name="form">
Check if
<input
type="checkbox"
id="IRF"
name='IRF'
/>

<input type="radio" value="Yes" name="SP" id="SP" required="yes" onclick="showhideSPForm(this.value)"/><label for="SP">Yes</label>

&nbsp;&nbsp;&nbsp;<input type="radio" value="No" name="SP" id="noSP" onclick="showhideSPForm(this.value)"/><label for="noSP">No</label>

<div id="div8" style="display:none">
<div class="clearfix">
<select name="SPECIAL" id="SPECIAL">
<option>Please Select</option>
<option
data-name="Animal Friend"
data-img="/images/img/AnimalFriend.png"
data-price="30"
value="1">Animal Friend</option>
<option
data-name="Aquaculture"
data-img="/images/img/Aquaculture.png"
data-price="25"
value="2">Aquaculture</option>
<option
data-name="Protect Our Oceans"
data-img="/images/img/ProtectOurOceans.png"
data-price="20"
value="3">Protect Our Oceans</option>
</select>
<!-- Modal -->
<div class="modal fade" id="modal_special" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Specialty Plate</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary accept">Accept</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="totalPrice"></div>

<div id="div9" style="display:none">
<!---You are not qualified to see this form.--->
</div>
<div id="totalPrice"></div>
</form>

最佳答案

我认为,您没有将 specialFee 重置为 0。

function showhideSPForm(SP) {
if (SP == "Yes") {
document.getElementById("div8").style.display = 'block';
document.getElementById("div9").style.display = 'none';
} else if (SP == "No") {
document.getElementById("div9").style.display = 'block';
document.getElementById("div8").style.display = 'none';
document.getElementById("SPECIAL").selectedIndex = 0;
}
specialFee = 0;
calculateTotal();
}

关于javascript - 单选按钮下拉弹窗费用清零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26551988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com