在复选框和文本框中添加值 [英] Add a Value in Checkbox and Textbox

查看:86
本文介绍了在复选框和文本框中添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将复选框的值添加到文本框中的值?如果勾选了复选框,那么它的值会被添加到stotal中,否则会被忽略?



HTML

 <  输入    type   =  text     id   = < span class =code-keyword> sff    value   =  10.57  /  >  
< input 类型 = text id = osf value = 100.25 / >
< 输入 type = 复选框 id = cb1 value = 35.00 / & gt;
< 输入 type = text id = 总计 / >





  function  subtotal(){
var a = $( #sff) .VAL();
var b = $( #osf )VAL();

var stotal = parseFloat (a, 10 )+ parseFloat (b, 10 )+ parseFloat (cbtotal, 10 );
$(' #total')。val(' $' + stotal.toFixed( 2 ));
}

解决方案

#SFF)VAL();
var b =


#OSF)VAL();

var stotal = parseFloat (a, 10 )+ parseFloat (b, 10 )+ parseFloat (cbtotal, 10 );


' #total')。val('

How will I add the value of my checkbox to the value in my textbox? If the checkbox is checked, then it's value is added to the stotal, if not it will be ignored?

HTML

<input type="text" id="sff" value="10.57"/>
<input type="text" id="osf" value="100.25"/>
<input type="checkbox" id="cb1" value="35.00"/>
<input type="text" id="total"/>



function subtotal(){
	var a = $("#sff").val();
	var b = $("#osf").val();
	
	var stotal = parseFloat(a, 10)+ parseFloat(b, 10)+ parseFloat(cbtotal, 10);
    $('#total').val('$' + stotal.toFixed(2));
}

解决方案

("#sff").val(); var b =


("#osf").val(); var stotal = parseFloat(a, 10)+ parseFloat(b, 10)+ parseFloat(cbtotal, 10);


('#total').val('


这篇关于在复选框和文本框中添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆