下拉菜单上的每字段Javascript函数
我一直在寻找如何最好地解决这个问题的帮助。我有3种不同的价格,当用户在下拉列表中单击“是”时,我想进入一个隐藏字段。请参见以下示例:下拉菜单上的每字段Javascript函数,javascript,jquery,Javascript,Jquery,我一直在寻找如何最好地解决这个问题的帮助。我有3种不同的价格,当用户在下拉列表中单击“是”时,我想进入一个隐藏字段。请参见以下示例: 三 不 对 两个 不 对 三 不 对 这是javascript,但我不知道如何根据每个字段使其工作。如果oneprice上的“是”,如何将其更改为“是”,然后将其添加到total_oneprice中?如果twoprice为“是”,则将其添加到total_twoprice中?如果threeprice为“是”,则将其添加到总价中 <script>
三
不
对
两个
不
对
三
不
对
这是javascript,但我不知道如何根据每个字段使其工作。如果oneprice上的“是”,如何将其更改为“是”,然后将其添加到total_oneprice中?如果twoprice为“是”,则将其添加到total_twoprice中?如果threeprice为“是”,则将其添加到总价中
<script>
$('select').on('change',function() {
$('select').filter(function() { return this.value === 'yes'; }).each(function() {
sum += +$(this).parent().find('input').val();
});
$ ('#total_threeprice').val( sum.toFixed(2));
calculate();
});
</script>
$('select')。在('change',function()上{
$('select').filter(function(){返回this.value=='yes';}){
sum+=+$(this.parent().find('input').val();
});
美元("总价").val(总和固定(2));;
计算();
});
试试这个
$('select').on('change',function(){
if($(this).find('option[value*=yes]').is(':selected'))
{
var nr = $(this).attr('name').replace('switch','');
$("[name*='total_"+nr+"price']").val($("input[name*='"+nr+"price']").val());
}
})
下面是实现这一点的诀窍:
$('select').live('change',function() {
if($(this).val() == 'yes')
{
var id = this.id;
$('input.test1#'+id).val($('input.test#'+id).val())
}
else
{
$('input.test1#'+this.id).val("");
}
});
这是请做一个jsfiddle。我不明白你为什么需要使用下拉菜单来做这件事。如果您只有3个带有值的复选框并使用表单(无需javascript),则更为实用。
#threeprice
不存在。geekymartian不确定你是否明白我想做什么,所以我不认为你能做出那种评论。对不起,错了。
$('select').live('change',function() {
if($(this).val() == 'yes')
{
var id = this.id;
$('input.test1#'+id).val($('input.test#'+id).val())
}
else
{
$('input.test1#'+this.id).val("");
}
});