有谁知道我可以实现以下目标的方法?
当用户在输入框中输入 1 时,会弹出一个警报,但我希望用户能够确认新值并自动用最小值填充输入字段或取消并且该字段保持空白。
到目前为止,我有以下代码:
function Form_Validator(theForm)
{
var err = false;
var field;
var msg = 'Please correct the following to continue...\n';
var alpha = /\w/;
var numeric = /[^0-9^\s]/;
var emailvalidator = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
var teststr = '';
if(theForm.prod_quantity.value == '1'){
msg += '\nThe minimum order amount is 2.';
if (!err){
field = theForm.prod_quantity;
err = true;
}
}
if (!err){
return true;
}
else{
alert(msg);
field.focus();
return false;
}
}
<b>Quantity:</b> <input type="text" class="prod_quantity" name="prod_quantity" />
<input type="submit" value="" class="add-basket-btn"/>
我设法让一个警告框出现,但是我不知道如何让它自动填充,以便在他们点击确定时值变为 2。我希望这是有道理的。