gpt4 book ai didi

jquery - 使用 jQuery 以编程方式触发模糊事件

转载 作者:行者123 更新时间:2023-12-03 22:37:29 24 4
gpt4 key购买 nike

我有一个排序矩阵,其中包含 oneInput 类的输入行,并且我有一个 jquery 函数,该函数会触发任何这些输入的模糊事件,并对行和列求和,并将总和插入到正确的位置 --所有这一切都按照我的预期进行。

我想做的是在页面加载时将所有行和列与初始值相加。我正在 document.ready 上调用 init() 函数,并且我尝试了以下两种方法但没有成功。

function init(){
$('.oneInput').trigger('blur');
}

function init(){
$('.oneInput').each(function(){
$(this).trigger('blur');
});
}

该模糊事件触发的函数是这样的:

$(".oneInput").blur(function(){
// Tally Row
var thisRow = $(this).closest('tr');
var rowTotal = 0;
thisRow.find('input.oneInput').each(function() {
var n = parseFloat(this.value);
if(!isNaN(n))
rowTotal += n;
});
$(this).parent().parent().find( 'input.screenOneTotal').empty().val( rowTotal );

// Tally Column
var colName = $(this).attr('name');
var col = colName.substr(0,3);
var spanName = "input#tot"+col;
var tot = parseInt($("input[name='"+col+"1']").val())+parseInt($("input[name='"+col+"2']").val())+parseInt($("input[name='"+col+"3']").val())+parseInt($("input[name='"+col+"4']").val())+parseInt($("input[name='"+col+"5']").val())+parseInt($("input[name='"+col+"6']").val())+parseInt($("input[name='"+col+"7']").val())+parseInt($("input[name='"+col+"8']").val())+parseInt($("input[name='"+col+"9']").val())+parseInt($("input[name='"+col+"10']").val())+parseInt($("input[name='"+col+"11']").val())+parseInt($("input[name='"+col+"12']").val());
$(spanName).empty().val(tot);

//GRAND TOTAL
var gTotalOne = parseInt($("#totLIB").html())+parseInt($("#totRPI").html())+parseInt($("#totLMM").html());
$("#scrOneTotal").empty().html(gTotalOne);
}); // end inputOne blur

如果需要,我可以提供页面代码的其余部分,但它是在 php 中并且需要数据库。

最佳答案

只需将 .blur() 添加到 blur 函数的末尾,它将在 DOM 就绪时调用它:

$(".oneInput").blur(function(){
//code code and more code
}).blur();

演示:http://jsfiddle.net/Exw3f/

关于jquery - 使用 jQuery 以编程方式触发模糊事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325004/

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