首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js或jquery 即时加减吗?解决方案

2012-03-21 
js或jquery 即时加减吗?在文本框左边放一加号右边放一个减号,点击加号数值加1(或0.5)点击减号减1(或0.5),

js或jquery 即时加减吗?
在文本框左边放一加号右边放一个减号,点击加号数值加1(或0.5)点击减号减1(或0.5),文本框的初始值是零
具体效果像这个网页:http://www.codefans.net/jscss/code/2430.shtml 谢谢各位了。

[解决办法]
你发的那个链接稍微改下不就行了,不会改吗。。

HTML code
<!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>无标题文档</title></head><body>    <span id="add">+</span>    <input type="text" value="0" id="text"/>    <span id="reduce">-</span>    <script>        function $(id){            return document.getElementById(id);        }        var elems = {            add: $('add'),            reduce: $('reduce'),            text: $('text')        }        elems.add.onclick = function(){            elems.text.value++;        }        elems.reduce.onclick = function(){            elems.text.value--;        }    </script></body></html>
[解决办法]
HTML code
<html><head>    <title></title>    <style type="text/css">        span        {            border: 1px solid gray;            cursor: pointer;            color: Gray;            height: 2px;            width: 2px;        }    </style>    <script type="text/javascript">        function autoPlusMinus() {            var operator = event.srcElement.innerText;            if (operator != "+" && operator != "-") {                return;            }            var oldValue = number.value;            if (isNaN(oldValue)) {                number.value = "0";            }            oldValue = parseFloat(number.value);            number.value = eval(oldValue + operator + 1).toString();        }        document.onclick = autoPlusMinus;    </script></head><body>    <span id="plus">+</span>&nbsp;<input id="number" type="text" value="0" style="width: 40px;        text-align: center;" />&nbsp;<span id="minus">-</span></body></html> 

热点排行
Bad Request.