我有一个 jQuery .change 的小问题,当我点击数据时,数据没有改变。我正在使用 ddSlick。我想达到的效果是这样的:http://www.convertmymoney.com/ - 因此,当输入金额时,数据已经另外改变,当有人输入金额并更改货币(标志)时,它也会改变数据,不幸的是我的情况并非如此。$(document).ready(function() { var total = 0; $("#amountin, #amountout,#amountValue").on("change", function() { cal(); }); $("#amountValue").on("keydown", function() { cal(); }); $("#exchange").on("click", function() { var amountinval = $("#amountin").val(); var amountoutval = $("#amountout").val(); cal(); }); function cal() { var amountinval = $("#amountin").val(); var amountoutval = $("#amountout").val(); var amountValue = $("#amountValue").val(); total = parseFloat(amountValue * (amountinval / amountoutval)).toFixed(2); $('#totavalue').attr('placeholder', total); }});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div class="currency-calc-in__input currency-calc__input col-lg-8 col-sm-6 col-md-6 col-6"> <label for="amountValue" class="currency-calc__label">Kwota (posiadam)</label> <input type="number" class="form-control" id="amountValue" name="amountValue" aria-describedby="numberHelp" placeholder="100"></div><select class="custom-select currency-calc-in__slick" id="amountin" name="amountin"> <option value="1" data-description="PLN" data-value="1" data-symbol="PLN">Polski złoty</option> <option value="0.1286" data-description="THB" data-value="0.1286" data-symbol="THB">Bat tajlandzki</option> <option value="4.1886" data-description="USD" data-value="4.1886" data-symbol="USD">Dolar amerykański</option> <option value="2.6503" data-description="AUD" data-value="2.6503" data-symbol="AUD">Dolar australijski</option> <option value="0.5406" data-description="HKD" data-value="0.5406" data-symbol="HKD">Dolar Hongkongu</option></select>
2 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
您是否尝试过用 cal() 函数替换此处的 console.log ?
$('.currency-calc-in__slick').ddslick({
imagePosition: "right",
selectText:"Wybierz",
onSelected: function (data) {
cal();
}
});
$('.currency-calc-out__slick').ddslick({
imagePosition: "right",
defaultSelectedIndex:3,
onSelected: function (data) {
cal();
}
});
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
这两行返回未定义
var amountinval = $("#amountin").find('.dd-selected-value').val();
var amountoutval = $("#amountout").find('.dd-selected-value').val();
尝试用以下内容替换它们,它将返回所选的选项值
var amountinval = $("#amountin :selected").val();
var amountoutval = $("#amountout :selected").val();
- 2 回答
- 0 关注
- 93 浏览
添加回答
举报
0/150
提交
取消