gpt4 book ai didi

javascript - 如何使用 Jquery .find() 查找已使用 .load() 加载的元素

转载 作者:行者123 更新时间:2023-11-27 23:56:58 25 4
gpt4 key购买 nike

我需要在div中加载一个html文件,这个html里面有很多元素。文件加载后不久,在 div 内,我需要在该 html 内找到一个特定元素,以更改其值。

我正在使用以下代码:

var div = document.createElement('div'); 
$("#emptySpacee").append(div); // insert the new div into the DOM
$(div).load('html/page.html', function(){ // load the page
$(div).find(".fieldName").val(1234); //search using class name
});

文档已加载,但使用 jquery .find() 我无法获取该元素。

我读了很多关于这个问题的帖子,看起来一切都取决于我正在搜索元素但该元素尚未在 DOM 中创建的事实。

当加载了 html 文件的所有元素都可以使用 Jquery.find() 函数搜索时,我应该怎么做才能开始搜索?

最佳答案

尝试选择 $("#emptySpacee").find(div).load() 链接到 ,使用 $(this).find( .load() 回调中的“.fieldName”).val(1234)

var div = document.createElement('div'); 
var name = $.now();
div.className = name;
$("#emptySpacee").append(div); // insert the new div into the DOM
$("#emptySpacee").find("[class=" + name + "]").load('html/page.html', function(){ // load the page
$(this).find(".fieldName").val(1234); //search using class name
});

关于javascript - 如何使用 Jquery .find() 查找已使用 .load() 加载的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32183934/

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