Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery .text()未提取名称? 发生了什么事_Jquery_Html - Fatal编程技术网

Jquery .text()未提取名称? 发生了什么事

Jquery .text()未提取名称? 发生了什么事,jquery,html,Jquery,Html,我想要什么 当我点击.student框的.icon铅笔圈时,我想复制.student name中的姓名,并将其放入的.student name中 除了我这样做之外,#弹出窗口rename.student name中显示的所有内容都是一个空白框。出于某种原因,没有什么是复制 在将名称复制到selectedStudentName中时,我无法确定是否选择了错误的对象,或者.text()是否不起作用 如果有人能在这方面帮助我,我将不胜感激 我的代码 HTML 我从来没有使用过$(this).closes

我想要什么 当我点击
.student框的
.icon铅笔圈
时,我想复制
.student name
中的姓名,并将其放入
.student name

除了我这样做之外,
#弹出窗口rename.student name
中显示的所有内容都是一个空白框。出于某种原因,没有什么是复制

在将名称复制到
selectedStudentName
中时,我无法确定是否选择了错误的对象,或者
.text()
是否不起作用

如果有人能在这方面帮助我,我将不胜感激

我的代码 HTML

我从来没有使用过$(this).closest();选择器。我会更具体的选择你。我用它来处理。parentsUntil()。下面将抓取.student框(一个家长缺少.student行),然后找到标记以获取文本内容。另外,您的JS Fiddle没有包含jQuery,因此如果您在Javascript设置中进行测试,请确保在Javascript设置中选择该选项

selectedStudentName = $(this).parentsUntil('.student-row').find('.student-name h1').text();

最近的函数无法按预期工作,因为此函数查找第一个祖先,请检查此$(“.student name>h1”).text()而不是$(this)。最近的(..).text()将得到您想要的结果。因此,嗯。。。您的代码以某个圆形图标为目标,但所述dom节点不在示例代码中。我们应该如何帮助?检查我的最新答案
$(document).ready(function(){

    var selectedStudentName = "Student Name";
    $('.student-box').on('click','.icon-pencil-circle',function(){
        selectedStudentName = $(this).closest('.student-name').text();
        $('#popup-rename').find('.student-name').text(selectedStudentName);
    });
})
selectedStudentName = $(this).parentsUntil('.student-row').find('.student-name h1').text();