gpt4 book ai didi

javascript - 将 .load html 文件的内容存储在变量中

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

单击按钮时,我将 tfoot 附加到 tabletfoot 的内容是 .load 到本地 .html 文件的结果。尽管我的解决方案有效,但每次单击时我都会执行对 .html 文件的访问。第一次点击的结果可以存储在变量中并重复使用吗?

$scope.btnClick = function() {

var tfoot = $('#datepicker table').find('tfoot');
if(!tfoot.length) {
tfoot = $('<tfoot>').appendTo('#datepicker table');
}

tfoot.load('myDir/calendar/customFooter.html');

}

最佳答案

您可以通过在 load() 方法上使用回调来存储结果来实现这一点。我为此使用了您的 $scope 变量,但您可以根据需要修改它。试试这个:

$scope.btnClick = function() {    
var tfoot = $('#datepicker table').find('tfoot');
if (!tfoot.length) {
tfoot = $('<tfoot>').appendTo('#datepicker table');
}

if ($scope.tfootContent) {
tfoot.html($scope.tfootContent);
} else {
tfoot.load('myDir/calendar/customFooter.html', function(response) {
$scope.tfootContent = response;
});
}
}

关于javascript - 将 .load html 文件的内容存储在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38200821/

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