如何在不单击按钮的情况下将两个值相乘 - javascript [英] How to multiply two values without clicking a button - javascript

查看:71
本文介绍了如何在不单击按钮的情况下将两个值相乘 - javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的小提琴

http:// jsfiddle.net/YFgkB/6/

 <input type="text" name="input1" id="input1" value="5">
 <input type="text" name="input2" id="input2" value="">
 <a href="javascript: void(0)" onClick="calc()">Calculate</a>
 <input type="text" name="output" id="output" value="">

Javascript

Javascript

 function calc(){
   var textValue1 = document.getElementById('input1').value;
   var textValue2 = document.getElementById('input2').value;

   document.getElementById('output').value = textValue1 * textValue2; 
 }

这里一切正常,当点击计算链接时,它会将两个文本输入相乘数字并在第三个框中显示结果,但我需要它与链接计算自动乘法。

Here everything working fine when click on calculate link, it multiplies both the text input numbers and shows the result in the third box but I need it to automatic multiplication with the link calculate.

我的意思是用户可以在第二个文本框中输入一个值,这样它就可以自动进行混搭,并在没有任何按钮的情况下在第三个文本框中显示结果。

I mean user can enter a value in the 2nd text box so it automatically multplies and shows the result in the 3rd textbox without any button.

推荐答案

正在使用 DEMO



试试这个

Working DEMO

Try this

$("#input2,#input1").keyup(function () {
    $('#output').val($('#input1').val() * $('#input2').val());
});

这篇关于如何在不单击按钮的情况下将两个值相乘 - javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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