帮助使用 javascript 在标签中显示成本

发布于 2024-09-25 09:12:11 字数 218 浏览 0 评论 0原文

我对 javascript 完全陌生,我想知道是否有人可以帮助我完成一个简单的查询!

我有以下代码: http://jsfiddle.net/J47E6/

我已经设法让隐藏/显示功能正常工作,但我正在努力解决的是让价格显示在标签上。

有人能指出我正确的方向吗?

I'm completely new to javascript and I was wondernig if someone could help me with probably a simple query!

I have the following code:
http://jsfiddle.net/J47E6/

I've managed to get the hide/show functions to work, but what I'm struggling with is getting the price to display in the label.

Can someone point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧街凉风 2024-10-02 09:12:11

您的脚本的新版本现已更正。我注意到您在 jQuery (#) 中错过了折扣选择的 id 选择器。

该方法现在有效,但问题是,我不确定如何计算你的数学,因此我无法完成它。

$('#discountselection').hide();
$('#costlabel').hide();

$('#No').click(function() {
    $('#discountselection').hide();
    $('#costlabel').hide();
});

$('#Yes').click(function() {
    $('#discountselection').show();
    $('#costlabel').show();
});


$("#discountselection").change(function()  { 

var selected_value = $("#discountselection option:selected").val();

alert("Selected Value = " + selected_value);
var discount = {1: 12, 2: 24, 3: 36};

var package_prices = {'standard': 45, 'premium': 85, 'platinum': 134 };

var cost = 2; //package_prices[package] * discount[discountselection];
alert("Cost " + cost);
$("#costlabel").val(cost);

});

“package”和“discountSelection”从何而来。回答这些问题,我们就会为您完成。

package_prices[package] * discount[discountselection];

New version of your script is now corrected. I noticed you missed an id selector in your jQuery (#) for discountSelection.

The method now works, but problem is, I'm unsure of how to caculate your math therefor I cannot complete it.

$('#discountselection').hide();
$('#costlabel').hide();

$('#No').click(function() {
    $('#discountselection').hide();
    $('#costlabel').hide();
});

$('#Yes').click(function() {
    $('#discountselection').show();
    $('#costlabel').show();
});


$("#discountselection").change(function()  { 

var selected_value = $("#discountselection option:selected").val();

alert("Selected Value = " + selected_value);
var discount = {1: 12, 2: 24, 3: 36};

var package_prices = {'standard': 45, 'premium': 85, 'platinum': 134 };

var cost = 2; //package_prices[package] * discount[discountselection];
alert("Cost " + cost);
$("#costlabel").val(cost);

}); ​

Where does 'package' and 'discountSelection' come from. answer those and this'll be done for you.

package_prices[package] * discount[discountselection];
烈酒灼喉 2024-10-02 09:12:11

看一下:修改后的代码

JS 中有很多错误,标记也不一致。

Have a look at: revised code

There were a number of errors in JS and inconsistencies in the markup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文