我有输入字段(天数),带有增加和减少按钮以及“从”和“到”日期字段。
当用户通过单击+/-按钮选择“天数”并选择“从日期开始”时,应基于天数自动计算结束日期。 另外,促销金额还应根据“促销金额”字段中的天数(按10 /天)计算。
天数字段HTML:-
#include<string>
#include<iostream>
#define FMT_HEADER_ONLY
#include <fmt/format.h>
void f(char* in){
fmt::format_to_n(in, 2,"{}{}", 42,'\0');
std::cout << in;
}
int main(){
char arr[]= "ABI";
f(arr);
}
<div class="field qty">
<label class="label"><?= $block->escapeHtml(__('No Of Days')) ?>:</label>
<div class="control">
<div class="cart-qty">
<div class="qty-ctl">
<button title="<?= __('Decrease') ?>" type="button" data-role="change_cart_qty" class="up" data-qty="-1" class="decrease"></button>
</div>
<input type="number" class="qty" name="qty" id="noofdays" maxlength="12" value="<?= $defaultNoofDays * 1 ?>" title="<?php echo __('Qty') ?>" class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($wmhelper->getNoofDaysValidation())) ?>" />
<div class="qty-ctl">
<button title="<?= __('Increase') ?>" type="button" data-role="change_cart_qty" data-qty="1" class="down"></button>
</div>
</div>
</div>
我想使用jQuery做到这一点,任何人都可以帮我这个忙。
我正在使用下面的jQuery代码,它给了我警报之前的点击值:-
<div class="control">
<label class="label"><?= $block->escapeHtml(__('Banner From')) ?>:</label>
<input type="text" name="promotion_from_date" id="promotion-from-date" class="input-text" value="" />
</div>
<div class="control">
<label class="label"><?= $block->escapeHtml(__('Banner To')) ?>:</label>
<input type="text" name="promotion_to_date" id="promotion-to-date" class="input-text" value=""/>
</div>
我想用来获得点击后价值的事件。
答案 0 :(得分:0)
让我给您一个简单的例子,如果您使用的是datepicker
,它将可以正常工作。
它将根据天数变化以及promotion-to-date
promotion-from-date
DateChangeWithDays();
function DateChangeWithDays()
{
var days = parseInt($('#noofdays').val());
var nextDayDate = $('#promotion-from-date').datepicker('getDate', '+'+days+'d');
nextDayDate.setDate(nextDayDate.getDate() + days);
$('#promotion-to-date').datepicker('setDate',nextDayDate);
return true;
}
现在使用日期更改事件和promotion-from-date
选择器调用此函数....
$('#promotion-from-date, #noofdays').change(function()
{
DateChangeWithDays();
}