如何计算下拉值jQuery
当我仅选择第一个下拉列表时,#output 中的结果显示 NaN?
http://jsfiddle.net/boyee007/TJcP4/
我想要,如果选择第一个下拉列表显示 30 那么如果两个都选择将计算两个值
<select id="t_dermal_name">
<option value="1" rel="30">Between Eyebrows</option>
<option value="7" rel="30">Individual Line Softening</option>
<option value="2" rel="30">Lip Contouring</option>
</select>
<select id="t_wrinkle_name">
<option value="1" rel="30">Between Eyebrows</option>
<option value="7" rel="30">Individual Line Softening</option>
<option value="2" rel="30">Lip Contouring</option>
</select>
var output = 0;
var output1 = 0;
if($("#t_dermal_name").val() != 0){
enter code here`output = $("#t_dermal_name").find('option:selected').attr('rel');
}
if($("#t_wrinkle_name").val() != 0){
output1 = $("#t_wrinkle_name").find('option:selected').attr('rel');
}
$("#output").html(parseInt(output) + parseInt(output1));
when i select only the first dropdown, the result in #output showing NaN?
http://jsfiddle.net/boyee007/TJcP4/
i want, if the first dropdown is selected is showing 30 then if both selected will calculate the both value
<select id="t_dermal_name">
<option value="1" rel="30">Between Eyebrows</option>
<option value="7" rel="30">Individual Line Softening</option>
<option value="2" rel="30">Lip Contouring</option>
</select>
<select id="t_wrinkle_name">
<option value="1" rel="30">Between Eyebrows</option>
<option value="7" rel="30">Individual Line Softening</option>
<option value="2" rel="30">Lip Contouring</option>
</select>
var output = 0;
var output1 = 0;
if($("#t_dermal_name").val() != 0){
enter code here`output = $("#t_dermal_name").find('option:selected').attr('rel');
}
if($("#t_wrinkle_name").val() != 0){
output1 = $("#t_wrinkle_name").find('option:selected').attr('rel');
}
$("#output").html(parseInt(output) + parseInt(output1));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我冒昧地更新了您的示例。
这是您正在寻找的功能吗?
I took the liberty to update your example.
Is this the functionality you were looking for?
您的
t_dermal_name
ID 重复了两次。您的意思可能是第二个是t_wrinkle_name
。这还不包括
在此处输入代码
output = ...` 部分:)You have
t_dermal_name
id repeated twice. You probably meant second one to bet_wrinkle_name
.And that's not counting
enter code here
output = ...` part :)由于未设置
output1
,因此parseInt(output1)
== NaN(非数字)。当您将其添加到任何其他数字(即来自parseInt(output)
的值)时,总数仍为 NaN。在尝试解析并添加它之前,您应该检查 output1 是否已设置。
Because
output1
isn't set, soparseInt(output1)
== NaN (Not A Number). When you add this to any other number (i.e. the value fromparseInt(output)
) the total remains NaN.You should check that output1 is set before attempting to parse it and add it.
试试这个
Try this