我为文本框 div 编写了一个 ajax 函数 onmouseleave-6ren">
gpt4 book ai didi

javascript - 获取文本框的前一个值

转载 作者:行者123 更新时间:2023-11-30 16:55:50 25 4
gpt4 key购买 nike

我有一个用于 codeigniter 购物车数量的文本框。

<input type="text" id="txt-box_one<?php echo $items['id']; ?><?php echo $items['rowid'] ?>" value="<?php echo $items['qty']; ?> " class="small-txtbox">

我为文本框 div 编写了一个 ajax 函数 onmouseleave

如果用户首先将文本框值输入为 4 并在第二次将其更改为 0 意味着我想将文本框值更改为 4 再次。

js代码:

function chng(id,rowid,divid,pid,price,divtotal)
{
var inc = $('#'+id).val();
var upd = 'update';
if(inc < 1)
{
// $('#'+id).val('1');
var retVal = confirm("Are You Sure to Remove This Item From Baskets?");
if( retVal == true ){
var inc = 0;
}
else { { $('#'+id).val(1); var inc = 1; } }

}

$.ajax({
type: "POST",
data: "qty="+inc+"&row="+rowid+"&upd="+upd+"&pid="+pid+"&price="+price,
url: "<?php echo base_url('grocery/text')?>",
success: function(html){
$('#'+divid).html(html);
if( retVal == true ){
location.reload();
}
}
});

}

最佳答案

您也可以尝试这种 jQuery 方法

var count;
$("#count").on("keyup",function(){
if($(this).val() == 0)
return;

count = $(this).val();

});

$("#count").on("blur",function(){
if($(this).val() == 0){
$(this).val(count);
}
});

DEMO

关于javascript - 获取文本框的前一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29741242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com