<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题</title>
<script type="text/javascript">
function sum(obj) {
var z = document.getElementById("z")
var a = document.getElementById("a")
var b = document.getElementById("b")
var c = document.getElementById("c")
all.value=parseInt(z.value)
if(a.value!='')
{
y.value=parseInt(a.value)
h.value=parseInt(z.value)-parseInt(a.value)
}
if(a.value!=''&&b.value!='')
{
y.value=parseInt(b.value)+parseInt(a.value)
h.value=parseInt(z.value)-parseInt(a.value)-parseInt(b.value)
}
if(a.value!=''&&b.value!=''&&c.value!='')
{
y.value=parseInt(b.value)+parseInt(a.value)+parseInt(c.value)
h.value=parseInt(z.value)-parseInt(a.value)-parseInt(b.value)-parseInt(c.value)
}
}
</script>
</head>
<body>
总分:<input type="text" id="z" οnkeyup="sum(this)" />
<input type="text" id="a" οnkeyup="sum(this)" />
<input type="text" id="b" οnkeyup="sum(this)" />
<input type="text" id="c" οnkeyup="sum(this)" />
总分:<input type='text' id='all' style="border:0px solid whitewidth:25px" />
已选:<input type='text' id='y' style="border:0px solid whitewidth:25px" />
还剩:<input type='text' id='h' style="border:0px solid whitewidth:25px" />
</body>
</html>
扩展资料
js实现input的赋值
<input id="name1" name="teacherName" type="text" />
$('#name1').val('值')
document.getElementById('name1').value='值'
document.getElementById('name1').html('值')
document.getElementById('name1').attr('值')
document.getElementById('name1').innerText = '值'
<input class="easyui-textbox" id="name" name="teacherName" type="text" />
$('#name').textbox('setValue','值')
var val = $("#name").textbox('getValue')
let 公式=(b,c,d)=>
{
return b+c+d
}
let a
a=公式(1,2,3)
console.log(a)
a=公式(4,5,6)
console.log(a)
a=公式(7,8,9)
console.log(a)
运行如图: