我创建了一个包含输入项目的列表,如下所示。
在jquery中我创建了几个函数(根据Formula
值更改Balance
文本,更改Balance
输入的格式,并删除列表项)。最初所有功能都有效,但当我点击Add Item +
并尝试触发新项目列表上的功能时,它不起作用。
我不知道为什么会这样。任何帮助赞赏! :)
var tempMulti;
$(document).ready(function() {
resizeMultiPadding();
tempMulti = $(".multi-list").html();
});
$(window).resize(function() {
resizeMultiPadding();
});
function resizeMultiPadding() {
if ($(window).width() >= 576) {
var padding = $(window).width() * 0.04;
$(".multi-col").css({"padding-right": padding + "px"});
$(".multi-col:last-child").css({"padding-right": "0"});
$(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
}
else {
$(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
}
}
$(".spinner-up").click(function() {
var amount = parseInt($(this).parent().prev().prev().val()) || 0;
amount += 1;
$(this).parent().prev().prev().val(amount);
});
$(".spinner-down").click(function() {
var value = $(this).parent().prev().prev().val();
var amount = parseInt(value) || 0;
if (amount > 0) {
amount -= 1;
}
$(this).parent().prev().prev().val(amount);
});
(function($, undefined) {
"use strict";
$(function() {
var $form = $("#form-amount-input, .balance-group");
var $input = $form.find("input");
$input.on("keyup", function(event) {
var selection = window.getSelection().toString();
if (selection !== "") {
return;
}
if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
return;
}
var $this = $(this);
var input = $this.val();
input = input.replace(/[\D\s\._\-]+/g, "");
input = input ? parseInt(input, 10) : 0;
var formatted = input.toLocaleString("en-US");
$this.val(formatted);
$this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
if (formatted == "0") {
$this.parent().parent().parent().find(".panel-data-value").text("Formula");
}
});
});
})(jQuery);
$(".add-multi").click(function() {
$(".multi-list").prepend(tempMulti);
});
$(".multi-list-each-delete").click(function() {
$(this).parent().hide();
});
.form {
margin-bottom: 40px;
margin: 0 auto;
width: 768px;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 13px;
text-transform: uppercase;
color: #0099ff;
margin-bottom: 24px;
}
.input-text {
height: 34px;
border: solid 1px #c4c4c4;
width: 366px;
font-size: 13px;
padding: 0 12px 0 12px;
margin-bottom: 24px;
color: #333;
border-radius: 0;
background-color: transparent;
}
.input-text:focus {
border: solid 1px #00c983 !important;
}
::placeholder {
color: #c4c4c4;
font-size: 13px;
text-align: left !important;
}
.form-input-label {
display: block;
font-size: 12px;
font-weight: 700;
margin-bottom: 8px;
color: #333;
}
.input-disabled {
background-color: #eee;
}
.form-unit {
position: relative;
vertical-align: top;
}
.input-select-btn {
width: 34px;
height: 34px;
position: absolute;
top: 25px;
right: 0;
text-align: center;
line-height: 34px;
cursor: pointer;
z-index: -999;
}
.dropdown-btn-wrapper-clear {
border-left: solid 1px #c4c4c4;
}
.input-select-btn i {
color: #666 !important;
}
.on-disabled-btn {
border: solid 1px #c4c4c4;
background-color: #fff;
}
.input-select-btn i {
font-size: 12px;
color: #333;
}
.form-row {
display: block;
width: 100%;
margin: 0 !important;
}
.form-divided {
display: inline-block;
}
.form-divided-left {
margin-right: 32px;
}
.btn-label {
background-color: #eee;
}
.spinner-group {
position: absolute;
width: 16px;
height: 26px;
top: 4px;
right: 44px;
}
.spinner-up,
.spinner-down {
height: 13px;
line-height: 13px;
display: block;
}
.spinner-down {
top: 12px !important;
}
.spinner-up i,
.spinner-down i {
line-height: 13px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
.input-with-spinner {
text-align: right;
padding-right: 32px;
}
#amount-input {
width: 100% !important;
}
.amount-spinner-group {
right: 10px;
}
.add-multi {
height: 40px;
width: 100%;
text-align: center;
line-height: 40px;
border: dashed 2px #eaeaea;
font-size: 13px;
cursor: pointer;
margin-bottom: 8px;
}
.add-multi:hover {
background-color: #f8f8f8;
}
.add-multi i {
font-size: 10px;
transform: translateY(-1px);
margin-left: 4px;
}
.multi-list-each {
background-color: #f8f8f8;
display: block;
width: 100%;
padding: 16px 24px 12px;
position: relative;
margin-bottom: 8px;
}
.multi-list-each input {
background-color: #fff;
}
.multi-form-group {
position: relative;
width: 100%;
}
.multi-form-group input {
width: 100%;
margin-bottom: 0;
}
.spinner-group-year {
right: 2px;
}
#balance-currency {
position: absolute;
z-index: 99;
top: 0;
left: 0;
color: #333;
text-decoration: none;
}
.multi-col {
display: inline-block;
vertical-align: top;
padding-right: 16px;
padding-left: 16px;
}
.multi-col:first-child {
padding-left: 0;
}
.multi-col:last-child {
padding-right: 0;
}
.multi-col input {
margin-bottom: 0;
}
.multi-list-each-delete {
position: absolute;
right: 24px;
top: 50%;
transform: translateY(-50%);
}
.multi-list-each-delete i {
font-size: 12px;
}
@media (max-width: 767px) and (min-width: 576px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided-left {
margin-right: 24px;
}
.form-divided {
width: calc(50% - 14px);
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.input-select-btn {
right: 0;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
}
@media (max-width: 575px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided {
display: block;
width: 100%;
}
.form-divided-left {
margin-right: 0;
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
.multi-col {
margin-bottom: 16px;
padding-left: 0;
padding-right: 0 !important;
}
.multi-list-each-delete {
bottom: 8px;
top: auto;
left: 50%;
transform: translateX(-50%);
text-align: center;
color: #999;
}
.multi-list-each-delete .button:hover {
background-color: #eee;
color: #999;
text-decoration: none;
}
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
<div class="form">
<div class="form-row">
<div class="form-unit">
<div class="multi-attribute">
<label class="form-input-label">Multi-Attributes Input</label>
<div class="add-multi">Add item <i class="fas fa-plus"></i></div>
<ul class="multi-list">
<li class="multi-list-each">
<div class="col-33 multi-col">
<label class="form-input-label">Year</label>
<div class="multi-form-group">
<input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
<a />
<div class="spinner-group spinner-group-year">
<a class="spinner-up"><i class="fas fa-caret-up"></i></a>
<a class="spinner-down"><i class="fas fa-caret-down"></i></a>
</div>
</div>
</div>
<div class="col-33 multi-col">
<label class="form-input-label">Balance Increase</label>
<div class="balance-group multi-form-group">
<input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
<a />
<div class="spinner-group spinner-group-year">
<a class="spinner-up"><i class="fas fa-caret-up"></i></a>
<a class="spinner-down"><i class="fas fa-caret-down"></i></a>
</div>
</div>
</div>
<div class="col-33 multi-col">
<div class="panel-data panel-data-vertical">
<div class="panel-data-label">
Total Balance
</div>
<div class="panel-data-value">
Formula
</div>
</div>
</div>
<div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
答案 0 :(得分:2)
将$(".spinner-up")
更改为$(document).on("click",".spinner-up",function() {
您的其他一些元素也是如此。
工作演示
var tempMulti;
$(document).ready(function() {
resizeMultiPadding();
tempMulti = $(".multi-list").html();
});
$(window).resize(function() {
resizeMultiPadding();
});
function resizeMultiPadding() {
if ($(window).width() >= 576) {
var padding = $(window).width() * 0.04;
$(".multi-col").css({"padding-right": padding + "px"});
$(".multi-col:last-child").css({"padding-right": "0"});
$(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
}
else {
$(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
}
}
$(document).on("click",".spinner-up",function() {
var amount = parseInt($(this).parent().prev().prev().val()) || 0;
amount += 1;
$(this).parent().prev().prev().val(amount);
});
$(document).on("click",".spinner-down",function() {
var value = $(this).parent().prev().prev().val();
var amount = parseInt(value) || 0;
if (amount > 0) {
amount -= 1;
}
$(this).parent().prev().prev().val(amount);
});
(function($, undefined) {
"use strict";
$(function() {
var $form = $("#form-amount-input, .balance-group");
var $input = $form.find("input");
$input.on("keyup", function(event) {
var selection = window.getSelection().toString();
if (selection !== "") {
return;
}
if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
return;
}
var $this = $(this);
var input = $this.val();
input = input.replace(/[\D\s\._\-]+/g, "");
input = input ? parseInt(input, 10) : 0;
var formatted = input.toLocaleString("en-US");
$this.val(formatted);
$this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
if (formatted == "0") {
$this.parent().parent().parent().find(".panel-data-value").text("Formula");
}
});
});
})(jQuery);
$(document).on("click",".add-multi",function() {
$(".multi-list").prepend(tempMulti);
});
$(document).on("click",".multi-list-each-delete",function() {
$(this).parent().hide();
});
.form {
margin-bottom: 40px;
margin: 0 auto;
width: 768px;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 13px;
text-transform: uppercase;
color: #0099ff;
margin-bottom: 24px;
}
.input-text {
height: 34px;
border: solid 1px #c4c4c4;
width: 366px;
font-size: 13px;
padding: 0 12px 0 12px;
margin-bottom: 24px;
color: #333;
border-radius: 0;
background-color: transparent;
}
.input-text:focus {
border: solid 1px #00c983 !important;
}
::placeholder {
color: #c4c4c4;
font-size: 13px;
text-align: left !important;
}
.form-input-label {
display: block;
font-size: 12px;
font-weight: 700;
margin-bottom: 8px;
color: #333;
}
.input-disabled {
background-color: #eee;
}
.form-unit {
position: relative;
vertical-align: top;
}
.input-select-btn {
width: 34px;
height: 34px;
position: absolute;
top: 25px;
right: 0;
text-align: center;
line-height: 34px;
cursor: pointer;
z-index: -999;
}
.dropdown-btn-wrapper-clear {
border-left: solid 1px #c4c4c4;
}
.input-select-btn i {
color: #666 !important;
}
.on-disabled-btn {
border: solid 1px #c4c4c4;
background-color: #fff;
}
.input-select-btn i {
font-size: 12px;
color: #333;
}
.form-row {
display: block;
width: 100%;
margin: 0 !important;
}
.form-divided {
display: inline-block;
}
.form-divided-left {
margin-right: 32px;
}
.btn-label {
background-color: #eee;
}
.spinner-group {
position: absolute;
width: 16px;
height: 26px;
top: 4px;
right: 44px;
}
.spinner-up,
.spinner-down {
height: 13px;
line-height: 13px;
display: block;
}
.spinner-down {
top: 12px !important;
}
.spinner-up i,
.spinner-down i {
line-height: 13px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
.input-with-spinner {
text-align: right;
padding-right: 32px;
}
#amount-input {
width: 100% !important;
}
.amount-spinner-group {
right: 10px;
}
.add-multi {
height: 40px;
width: 100%;
text-align: center;
line-height: 40px;
border: dashed 2px #eaeaea;
font-size: 13px;
cursor: pointer;
margin-bottom: 8px;
}
.add-multi:hover {
background-color: #f8f8f8;
}
.add-multi i {
font-size: 10px;
transform: translateY(-1px);
margin-left: 4px;
}
.multi-list-each {
background-color: #f8f8f8;
display: block;
width: 100%;
padding: 16px 24px 12px;
position: relative;
margin-bottom: 8px;
}
.multi-list-each input {
background-color: #fff;
}
.multi-form-group {
position: relative;
width: 100%;
}
.multi-form-group input {
width: 100%;
margin-bottom: 0;
}
.spinner-group-year {
right: 2px;
}
#balance-currency {
position: absolute;
z-index: 99;
top: 0;
left: 0;
color: #333;
text-decoration: none;
}
.multi-col {
display: inline-block;
vertical-align: top;
padding-right: 16px;
padding-left: 16px;
}
.multi-col:first-child {
padding-left: 0;
}
.multi-col:last-child {
padding-right: 0;
}
.multi-col input {
margin-bottom: 0;
}
.multi-list-each-delete {
position: absolute;
right: 24px;
top: 50%;
transform: translateY(-50%);
}
.multi-list-each-delete i {
font-size: 12px;
}
@media (max-width: 767px) and (min-width: 576px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided-left {
margin-right: 24px;
}
.form-divided {
width: calc(50% - 14px);
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.input-select-btn {
right: 0;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
}
@media (max-width: 575px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided {
display: block;
width: 100%;
}
.form-divided-left {
margin-right: 0;
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
.multi-col {
margin-bottom: 16px;
padding-left: 0;
padding-right: 0 !important;
}
.multi-list-each-delete {
bottom: 8px;
top: auto;
left: 50%;
transform: translateX(-50%);
text-align: center;
color: #999;
}
.multi-list-each-delete .button:hover {
background-color: #eee;
color: #999;
text-decoration: none;
}
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
<div class="form">
<div class="form-row">
<div class="form-unit">
<div class="multi-attribute">
<label class="form-input-label">Multi-Attributes Input</label>
<div class="add-multi">Add item <i class="fas fa-plus"></i></div>
<ul class="multi-list">
<li class="multi-list-each">
<div class="col-33 multi-col">
<label class="form-input-label">Year</label>
<div class="multi-form-group">
<input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
<a />
<div class="spinner-group spinner-group-year">
<a class="spinner-up"><i class="fas fa-caret-up"></i></a>
<a class="spinner-down"><i class="fas fa-caret-down"></i></a>
</div>
</div>
</div>
<div class="col-33 multi-col">
<label class="form-input-label">Balance Increase</label>
<div class="balance-group multi-form-group">
<input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
<a />
<div class="spinner-group spinner-group-year">
<a class="spinner-up"><i class="fas fa-caret-up"></i></a>
<a class="spinner-down"><i class="fas fa-caret-down"></i></a>
</div>
</div>
</div>
<div class="col-33 multi-col">
<div class="panel-data panel-data-vertical">
<div class="panel-data-label">
Total Balance
</div>
<div class="panel-data-value">
Formula
</div>
</div>
</div>
<div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
答案 1 :(得分:1)
jquery与$(document).ready
上加载的DOM一起使用。要定位新元素,您需要编写如下函数:
$(document).on('handler', '#my-new-element-id', function()
{
alert('clicked the new guy')
})
答案 2 :(得分:1)
用此行替换onkeyup事件......
ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
05-29 15:35:08.591 24037-24037/com.cleatchaser D/FFmpeg: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/20180406_140202.mp4':
Metadata:
major_brand : isom
minor_version : 0
05-29 15:35:08.596 24037-24037/com.cleatchaser D/FFmpeg: compatible_brands: isom3gp4
creation_time : 2018-04-06 12:02:25
Duration: 00:00:15.06, start: 0.000000, bitrate: 17185 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17029 kb/s, 29.95 fps, 30 tbr, 90k tbn, 180k tbc (default)
05-29 15:35:08.601 24037-24037/com.cleatchaser D/FFmpeg: Metadata:
rotate : 90
creation_time : 2018-04-06 12:02:25
handler_name : VideoHandle
Side data:
05-29 15:35:08.606 24037-24037/com.cleatchaser D/FFmpeg: displaymatrix: rotation of -90.00 degrees
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 123 kb/s (default)
Metadata:
creation_time : 2018-04-06 12:02:25
05-29 15:35:08.611 24037-24037/com.cleatchaser D/FFmpeg: handler_name : SoundHandle
05-29 15:35:08.756 24037-24037/com.cleatchaser D/FFmpeg: Input #1, png_pipe, from '/storage/emulated/0/watermark.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 856x1324, 25 tbr, 25 tbn, 25 tbc
您需要创建一个直播事件,即使在设置事件后附加了元素,也会触发它。
$(document).on("keyup","#form-amount-input, .balance-group input",
&#13;
var tempMulti;
$(document).ready(function() {
resizeMultiPadding();
tempMulti = $(".multi-list").html();
});
$(window).resize(function() {
resizeMultiPadding();
});
function resizeMultiPadding() {
if ($(window).width() >= 576) {
var padding = $(window).width() * 0.04;
$(".multi-col").css({"padding-right": padding + "px"});
$(".multi-col:last-child").css({"padding-right": "0"});
$(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
}
else {
$(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
}
}
$(".spinner-up").click(function() {
var amount = parseInt($(this).parent().prev().prev().val()) || 0;
amount += 1;
$(this).parent().prev().prev().val(amount);
});
$(".spinner-down").click(function() {
var value = $(this).parent().prev().prev().val();
var amount = parseInt(value) || 0;
if (amount > 0) {
amount -= 1;
}
$(this).parent().prev().prev().val(amount);
});
(function($, undefined) {
"use strict";
$(function() {
var $form = $("#form-amount-input, .balance-group");
var $input = $form.find("input");
$(document).on("keyup","#form-amount-input, .balance-group input", function(event) {
var selection = window.getSelection().toString();
if (selection !== "") {
return;
}
if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
return;
}
var $this = $(this);
var input = $this.val();
input = input.replace(/[\D\s\._\-]+/g, "");
input = input ? parseInt(input, 10) : 0;
var formatted = input.toLocaleString("en-US");
$this.val(formatted);
$this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
if (formatted == "0") {
$this.parent().parent().parent().find(".panel-data-value").text("Formula");
}
});
});
})(jQuery);
$(".add-multi").click(function() {
$(".multi-list").prepend(tempMulti);
});
$(".multi-list-each-delete").click(function() {
$(this).parent().hide();
});
&#13;
.form {
margin-bottom: 40px;
margin: 0 auto;
width: 768px;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 13px;
text-transform: uppercase;
color: #0099ff;
margin-bottom: 24px;
}
.input-text {
height: 34px;
border: solid 1px #c4c4c4;
width: 366px;
font-size: 13px;
padding: 0 12px 0 12px;
margin-bottom: 24px;
color: #333;
border-radius: 0;
background-color: transparent;
}
.input-text:focus {
border: solid 1px #00c983 !important;
}
::placeholder {
color: #c4c4c4;
font-size: 13px;
text-align: left !important;
}
.form-input-label {
display: block;
font-size: 12px;
font-weight: 700;
margin-bottom: 8px;
color: #333;
}
.input-disabled {
background-color: #eee;
}
.form-unit {
position: relative;
vertical-align: top;
}
.input-select-btn {
width: 34px;
height: 34px;
position: absolute;
top: 25px;
right: 0;
text-align: center;
line-height: 34px;
cursor: pointer;
z-index: -999;
}
.dropdown-btn-wrapper-clear {
border-left: solid 1px #c4c4c4;
}
.input-select-btn i {
color: #666 !important;
}
.on-disabled-btn {
border: solid 1px #c4c4c4;
background-color: #fff;
}
.input-select-btn i {
font-size: 12px;
color: #333;
}
.form-row {
display: block;
width: 100%;
margin: 0 !important;
}
.form-divided {
display: inline-block;
}
.form-divided-left {
margin-right: 32px;
}
.btn-label {
background-color: #eee;
}
.spinner-group {
position: absolute;
width: 16px;
height: 26px;
top: 4px;
right: 44px;
}
.spinner-up,
.spinner-down {
height: 13px;
line-height: 13px;
display: block;
}
.spinner-down {
top: 12px !important;
}
.spinner-up i,
.spinner-down i {
line-height: 13px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
.input-with-spinner {
text-align: right;
padding-right: 32px;
}
#amount-input {
width: 100% !important;
}
.amount-spinner-group {
right: 10px;
}
.add-multi {
height: 40px;
width: 100%;
text-align: center;
line-height: 40px;
border: dashed 2px #eaeaea;
font-size: 13px;
cursor: pointer;
margin-bottom: 8px;
}
.add-multi:hover {
background-color: #f8f8f8;
}
.add-multi i {
font-size: 10px;
transform: translateY(-1px);
margin-left: 4px;
}
.multi-list-each {
background-color: #f8f8f8;
display: block;
width: 100%;
padding: 16px 24px 12px;
position: relative;
margin-bottom: 8px;
}
.multi-list-each input {
background-color: #fff;
}
.multi-form-group {
position: relative;
width: 100%;
}
.multi-form-group input {
width: 100%;
margin-bottom: 0;
}
.spinner-group-year {
right: 2px;
}
#balance-currency {
position: absolute;
z-index: 99;
top: 0;
left: 0;
color: #333;
text-decoration: none;
}
.multi-col {
display: inline-block;
vertical-align: top;
padding-right: 16px;
padding-left: 16px;
}
.multi-col:first-child {
padding-left: 0;
}
.multi-col:last-child {
padding-right: 0;
}
.multi-col input {
margin-bottom: 0;
}
.multi-list-each-delete {
position: absolute;
right: 24px;
top: 50%;
transform: translateY(-50%);
}
.multi-list-each-delete i {
font-size: 12px;
}
@media (max-width: 767px) and (min-width: 576px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided-left {
margin-right: 24px;
}
.form-divided {
width: calc(50% - 14px);
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.input-select-btn {
right: 0;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
}
@media (max-width: 575px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided {
display: block;
width: 100%;
}
.form-divided-left {
margin-right: 0;
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
.multi-col {
margin-bottom: 16px;
padding-left: 0;
padding-right: 0 !important;
}
.multi-list-each-delete {
bottom: 8px;
top: auto;
left: 50%;
transform: translateX(-50%);
text-align: center;
color: #999;
}
.multi-list-each-delete .button:hover {
background-color: #eee;
color: #999;
text-decoration: none;
}
}
&#13;
答案 3 :(得分:1)
var tempMulti;
$(document).ready(function() {
resizeMultiPadding();
tempMulti = $(".multi-list").html();
});
$(window).resize(function() {
resizeMultiPadding();
});
function resizeMultiPadding() {
if ($(window).width() >= 576) {
var padding = $(window).width() * 0.04;
$(".multi-col").css({"padding-right": padding + "px"});
$(".multi-col:last-child").css({"padding-right": "0"});
$(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
}
else {
$(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
}
}
$(document).on("click",".spinner-up",function() {
var amount = parseInt($(this).parent().prev().prev().val()) || 0;
amount += 1;
$(this).parent().prev().prev().val(amount);
});
$(document).on("click",'.spinner-down',function() {
var value = $(this).parent().prev().prev().val();
var amount = parseInt(value) || 0;
if (amount > 0) {
amount -= 1;
}
$(this).parent().prev().prev().val(amount);
});
(function($, undefined) {
"use strict";
$(function() {
var $form = $("#form-amount-input, .balance-group");
var $input = $form.find("input");
$input.on("keyup", function(event) {
var selection = window.getSelection().toString();
if (selection !== "") {
return;
}
if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
return;
}
var $this = $(this);
var input = $this.val();
input = input.replace(/[\D\s\._\-]+/g, "");
input = input ? parseInt(input, 10) : 0;
var formatted = input.toLocaleString("en-US");
$this.val(formatted);
$this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
if (formatted == "0") {
$this.parent().parent().parent().find(".panel-data-value").text("Formula");
}
});
});
})(jQuery);
$(".add-multi").click(function() {
$(".multi-list").prepend(tempMulti);
});
$(".multi-list-each-delete").click(function() {
$(this).parent().hide();
});
&#13;
.form {
margin-bottom: 40px;
margin: 0 auto;
width: 768px;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 13px;
text-transform: uppercase;
color: #0099ff;
margin-bottom: 24px;
}
.input-text {
height: 34px;
border: solid 1px #c4c4c4;
width: 366px;
font-size: 13px;
padding: 0 12px 0 12px;
margin-bottom: 24px;
color: #333;
border-radius: 0;
background-color: transparent;
}
.input-text:focus {
border: solid 1px #00c983 !important;
}
::placeholder {
color: #c4c4c4;
font-size: 13px;
text-align: left !important;
}
.form-input-label {
display: block;
font-size: 12px;
font-weight: 700;
margin-bottom: 8px;
color: #333;
}
.input-disabled {
background-color: #eee;
}
.form-unit {
position: relative;
vertical-align: top;
}
.input-select-btn {
width: 34px;
height: 34px;
position: absolute;
top: 25px;
right: 0;
text-align: center;
line-height: 34px;
cursor: pointer;
z-index: -999;
}
.dropdown-btn-wrapper-clear {
border-left: solid 1px #c4c4c4;
}
.input-select-btn i {
color: #666 !important;
}
.on-disabled-btn {
border: solid 1px #c4c4c4;
background-color: #fff;
}
.input-select-btn i {
font-size: 12px;
color: #333;
}
.form-row {
display: block;
width: 100%;
margin: 0 !important;
}
.form-divided {
display: inline-block;
}
.form-divided-left {
margin-right: 32px;
}
.btn-label {
background-color: #eee;
}
.spinner-group {
position: absolute;
width: 16px;
height: 26px;
top: 4px;
right: 44px;
}
.spinner-up,
.spinner-down {
height: 13px;
line-height: 13px;
display: block;
}
.spinner-down {
top: 12px !important;
}
.spinner-up i,
.spinner-down i {
line-height: 13px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
.input-with-spinner {
text-align: right;
padding-right: 32px;
}
#amount-input {
width: 100% !important;
}
.amount-spinner-group {
right: 10px;
}
.add-multi {
height: 40px;
width: 100%;
text-align: center;
line-height: 40px;
border: dashed 2px #eaeaea;
font-size: 13px;
cursor: pointer;
margin-bottom: 8px;
}
.add-multi:hover {
background-color: #f8f8f8;
}
.add-multi i {
font-size: 10px;
transform: translateY(-1px);
margin-left: 4px;
}
.multi-list-each {
background-color: #f8f8f8;
display: block;
width: 100%;
padding: 16px 24px 12px;
position: relative;
margin-bottom: 8px;
}
.multi-list-each input {
background-color: #fff;
}
.multi-form-group {
position: relative;
width: 100%;
}
.multi-form-group input {
width: 100%;
margin-bottom: 0;
}
.spinner-group-year {
right: 2px;
}
#balance-currency {
position: absolute;
z-index: 99;
top: 0;
left: 0;
color: #333;
text-decoration: none;
}
.multi-col {
display: inline-block;
vertical-align: top;
padding-right: 16px;
padding-left: 16px;
}
.multi-col:first-child {
padding-left: 0;
}
.multi-col:last-child {
padding-right: 0;
}
.multi-col input {
margin-bottom: 0;
}
.multi-list-each-delete {
position: absolute;
right: 24px;
top: 50%;
transform: translateY(-50%);
}
.multi-list-each-delete i {
font-size: 12px;
}
@media (max-width: 767px) and (min-width: 576px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided-left {
margin-right: 24px;
}
.form-divided {
width: calc(50% - 14px);
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.input-select-btn {
right: 0;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
}
@media (max-width: 575px) {
.form {
padding-left: 16px;
padding-right: 16px;
width: 100%;
}
.form-divided {
display: block;
width: 100%;
}
.form-divided-left {
margin-right: 0;
}
.input-text,
textarea {
display: inline-block;
width: 100%;
}
.labeled-row {
display: block;
width: 100%;
}
.form-unit .select2-container, .form-unit .select2-selection {
width: 100% !important;
}
.multi-col {
margin-bottom: 16px;
padding-left: 0;
padding-right: 0 !important;
}
.multi-list-each-delete {
bottom: 8px;
top: auto;
left: 50%;
transform: translateX(-50%);
text-align: center;
color: #999;
}
.multi-list-each-delete .button:hover {
background-color: #eee;
color: #999;
text-decoration: none;
}
}
&#13;
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
<div class="form">
<div class="form-row">
<div class="form-unit">
<div class="multi-attribute">
<label class="form-input-label">Multi-Attributes Input</label>
<div class="add-multi">Add item <i class="fas fa-plus"></i></div>
<ul class="multi-list">
<li class="multi-list-each">
<div class="col-33 multi-col">
<label class="form-input-label">Year</label>
<div class="multi-form-group">
<input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
<a />
<div class="spinner-group spinner-group-year">
<a class="spinner-up"><i class="fas fa-caret-up"></i></a>
<a class="spinner-down"><i class="fas fa-caret-down"></i></a>
</div>
</div>
</div>
<div class="col-33 multi-col">
<label class="form-input-label">Balance Increase</label>
<div class="balance-group multi-form-group">
<input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
<a />
<div class="spinner-group spinner-group-year">
<a class="spinner-up"><i class="fas fa-caret-up"></i></a>
<a class="spinner-down"><i class="fas fa-caret-down"></i></a>
</div>
</div>
</div>
<div class="col-33 multi-col">
<div class="panel-data panel-data-vertical">
<div class="panel-data-label">
Total Balance
</div>
<div class="panel-data-value">
Formula
</div>
</div>
</div>
<div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
&#13;