带加减按钮的数字输入框(整理)

简介: 带加减按钮的数字输入框(整理)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>带加减按钮的数字输入框(整理)</title>
<script src="https://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<style>
body {
  margin:0;
  padding:0;
}
li{
  list-style: none;
}
.number-box {
  border:#e5e5e5 solid 1px;
  display:inline-block;
  overflow:hidden;
}
.number-box input[type='text'] {
  height:30px;
  border-top:none;
  border-bottom:none;
  border-left:#e5e5e5 solid 1px;
  border-right:#e5e5e5 solid 1px;
  margin:0;
  text-align:center;
  width:40px;
  outline:none;
  padding:0 5px;
  float:left;
  line-height:30px;
}
.number-box input[type='button'] {
  height:30px;
  width:40px;
  float:left;
  border:none;
  outline:none;
  background-color:#f3f3f3;
  line-height:30px;
  cursor:pointer;
  padding:0;
}
.number-box input[type='button']:hover {
  background-color:#f9f9f9;
}
.number-box input[type='button']:active {
  background-color:#f6f6f6;
}
</style>
</head>
<body>
<ul>
  <li>
      <div class="number-box">
          <input type="button" class="on-number" value="-" data-v="-1">
          <input type="text" value="0">
          <input type="button" class="on-number" value="+" data-v="1">
      </div>
  </li>
  <li>
      <div class="number-box">
          <input type="button" class="on-number" value="减" data-v="-1">
          <input type="text" value="-5">
          <input type="button" class="on-number" value="加" data-v="1">
      </div>
  </li>
  <li>
      <div class="number-box">
          <input type="button" class="on-number" value="减" data-v="-1">
          <input type="text" value="5">
          <input type="button" class="on-number" value="加" data-v="1">
      </div>
  </li>
</ul>
<script>
$(document.documentElement).on("click", ".on-number", function() {
    var $val = $(this).siblings("input[type='text']"),
        val = parseInt($val.val(), 10) + parseInt($(this).data("v"));
    $val.val(isNaN(val) ? 0 : val);
});
</script>
</body>
</html>

相关文章
|
7月前
|
Web App开发 C++
c++ 实现不在同一程序内,在光标处(当前有焦点的窗体输入框)输入字符
c++ 实现不在同一程序内,在光标处(当前有焦点的窗体输入框)输入字符
多行文本溢出省略号击展开收缩(整理)
多行文本溢出省略号击展开收缩(整理)
|
8月前
|
数据安全/隐私保护
uniapp自定义密码输入键盘-数字键盘效果demoUI方法一(整理)
uniapp自定义密码输入键盘-数字键盘效果demoUI方法一(整理)
|
8月前
|
数据安全/隐私保护
uniapp自定义密码输入键盘-数字键盘效果demoUI方法二(整理)
uniapp自定义密码输入键盘-数字键盘效果demoUI方法二(整理)
textarea文本域控制字数多少(带数字,数字减小)demo效果示例(整理)
textarea文本域控制字数多少(带数字,数字减小)demo效果示例(整理)
【C#】【平时练习】将左边列表框(List)的内容(月份)添加到右边列表框。最终右侧显示的内容(月份)要保持一定顺序
【C#】【平时练习】将左边列表框(List)的内容(月份)添加到右边列表框。最终右侧显示的内容(月份)要保持一定顺序
101 0
【C#】【平时练习】将左边列表框(List)的内容(月份)添加到右边列表框。最终右侧显示的内容(月份)要保持一定顺序
Excel - 表格设置数字下拉数值不变不递增
Excel - 表格设置数字下拉数值不变不递增
807 0
Excel - 表格设置数字下拉数值不变不递增
|
数据格式
在文本框中输入两个操作数和选择运算符后,在页面上显示输出结果
在文本框中输入两个操作数和选择运算符后,在页面上显示输出结果
376 0
在文本框中输入两个操作数和选择运算符后,在页面上显示输出结果