有3个文本框单价,数量,总价,都可以手动输入,并通过JS脚本根据相互输入的值进行价格自动调整
也就是说不管3者哪个改变都会对其他进行改变 当然每次只有一项改变 总价变的时候只改变数量
也就是说不管3者哪个改变都会对其他进行改变 当然每次只有一项改变 总价变的时候只改变数量
解决方案 »
- Jquery中使用propertygrid显示问题
- 使用confirm确认框时希望将焦点默认在取消按钮上
- 这段JS在FF下无效,哪里有问题呢??????
- rtsp流媒体协议在WEB上播放有什么好的播放器吗
- 关于正则表达式中()的一个问题,请大家帮忙
- 怎么把input的调用JS 变成A链接呢??
- (对话框式)强迫式修改主页的代码谁有?
- 怎样做一个检查系统字库的程序???
- 请问各位大侠如何在IE中嵌入一个插件,让该插件中的控件实现对文字属性操作及加入下划线?感谢回复。
- 关于新闻标题动态滚动的实现!---急-javascript高手请进!
- JS去除html内所有的class
- EXT JS中,使用regex判断可以为空的问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<script language=javascript>
function chengfa1()
{
text1 = document.getElementById('Text1');
text2 = document.getElementById('Text2');
text3 = document.getElementById('Text3');
if (text2.value !='' && text3.value !=''){text1.value = text3.value / text2.value};
}
function chengfa2()
{
text1 = document.getElementById('Text1');
text2 = document.getElementById('Text2');
text3 = document.getElementById('Text3');
if (text1.value !='' && text3.value !=''){text2.value = text3.value / text1.value};
}
function chengfa3()
{
text1 = document.getElementById('Text1');
text2 = document.getElementById('Text2');
text3 = document.getElementById('Text3');
if (text1.value !='' && text2.value !=''){text3.value = text1.value * text2.value};
}
</script>
</head>
<body>
<input id="Text1" type="text" onclick="chengfa1();" />
<input id="Text2" type="text" onclick="chengfa2();" />
<input id="Text3" type="text" onclick="chengfa3();" />
</body>
</html>JS水平太差了。。参考下吧。
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
function change(obj){
var price=document.getElementById('price');
var count=document.getElementById('count');
var total=document.getElementById('total');
if(obj.id=='price'){
total.value=price.value*count.value;
}
if(obj.id=='count'){
total.value=price.value*count.value;
}
if(obj.id=='total'){
count.value=Math.floor(total.value/price.value);
}
}
</script>
<BODY>
<div>
<input type="text" value="20" id="price" title="price" onChange="change(this)"/>
<input type="text" value="15" id="count" title="count" onChange="change(this)"/>
<input type="text" value="300" id="total" title="total" onChange="change(this)"/>
</div>
</BODY>
</HTML>
function doFun(ty){
if(ty=="1"){
var t1 = document.form1.txt1.value;
var t2 = document.form1.txt2.value;
var t3 = document.form1.txt3.value;
document.form1.txt3.value = t1 * t2;
}else if(ty=="2"){
var t1 = document.form1.txt1.value;
var t2 = document.form1.txt2.value;
var t3 = document.form1.txt3.value;
document.form1.txt3.value = t1 * t2;
}else if(ty=="3"){
var t1 = document.form1.txt1.value;
var t2 = document.form1.txt2.value;
var t3 = document.form1.txt3.value;
document.form1.txt2.value = t3 / t1;
}
}
</script>
<form name="form1">
单价:<input type="text" name="txt1" value="0" onchange="doFun('1')" />
数量:<input type="text" name="txt2" value="0" onchange="doFun('2')" />
总价:<input type="text" name="txt3" value="0" onchange="doFun('3')" />
</form>