[英]How to unfocus the user from the input box in a confirmation box using Jquery?
[英]Prefill input text box from confirmation box
有谁知道我可以实现以下目标的方法?
当用户在输入框中输入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。 我希望这是有道理的。
在条件中使用简单的confirm()
对话框而不是alert()
,并在输入框中设置所需的值:
if (confirm (msg)) { // ask for confirmation
// set the new value
theForm.prod_quantity.value = 2;
} else {
// leave the box blank
theForm.prod_quantity.value = '';
}
// ...
var orderAmount = confirm(msg);
if ( orderAmount ) theForm.prod_quantity.value = "2";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.