在文本框中preSS按钮,值增加 [英] press button and value increases in text box

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

问题描述

所以,当页面加载文本框将包含一个存储的值。我希望用户preSS的+按钮,然后在文本框将一个增加值。即时猜测这与jQuery做的......从哪里获取到目前为止开始任何想法我有...

So when the page loads the text box will contain a stored value. I want the user to press the '+' button and the value in the text box will increase by one. Im guessing this is done with JQuery...Any ideas on where to get started so far I have...

<input type="text" name="BoqTextBox" id="BoqTextBox" value="0" />  
    <input type="Button" value="+" onclick="AddOne(document.getElementById('BoqTextBox').value)" />

    <script>
        function Add(data) {
            //so the current digit is passed to here, where I need to do some funky code
            //where it increments the current digit by one and stores it in BoqTextBox - replacing the old digit.

            //Also to note if the text box contains 124.54 for example and + is pressed
            //then new value will be 125.54
        }
    </script>

与此任何帮助将是巨大的。

Any assistance with this would be great.

感谢您

...类似数据=数据+ 1,但我怎么返回值到文本框?

...something like data = data + 1, but then how do I return the value into the text box?

推荐答案

您可以使用jQuery的 VAL()获取和设置一个值。在这种情况下,code你需要看起来是这样的(演示):

You can use jQuery's val() to fetch and set a value. In this case the code you need could look like this (demo):

<input type="text" name="BoqTextBox" id="BoqTextBox" value="0" />
<input type="Button" id='AddButton' value="+" />
<script>
$('#AddButton').on('click', function () {
    var input = $('#BoqTextBox');
    input.val(parseFloat(input.val()) + 1);
})
</script>

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

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