Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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
从<;a>;使用jQuery的元素?_Jquery_Html_Select_Text - Fatal编程技术网

从<;a>;使用jQuery的元素?

从<;a>;使用jQuery的元素?,jquery,html,select,text,Jquery,Html,Select,Text,我正在尝试获取此html的文本部分: <li class="location"><a href="#">Some Text</a></li> 这样我的警报就会显示“一些文本”。我只是不确定它为什么不起作用。该方法是由jQuery包装器元素提供的,children('a')[0]给出了一个没有该方法的DOM元素 使用getter格式的text()返回给定集合中第一个元素的文本内容,这就是您要查找的内容 $('.location').off('cli

我正在尝试获取此html的文本部分:

<li class="location"><a href="#">Some Text</a></li>
这样我的警报就会显示“一些文本”。我只是不确定它为什么不起作用。

该方法是由jQuery包装器元素提供的,
children('a')[0]
给出了一个没有该方法的DOM元素

使用getter格式的
text()
返回给定集合中第一个元素的文本内容,这就是您要查找的内容

$('.location').off('click').click(function () {
    alert($(this).children('a').text());
});
该方法是由jQuery包装器元素提供的,
children('a')[0]
给出了一个没有该方法的DOM元素

使用getter格式的
text()
返回给定集合中第一个元素的文本内容,这就是您要查找的内容

$('.location').off('click').click(function () {
    alert($(this).children('a').text());
});
试一试

}))

试试看


}))

谢谢,我的代码的另一部分出现了一个小错误,但是你的回答对这个例子很有帮助。谢谢,我的代码的另一部分出现了一个小错误,但是你的回答对这个例子很有帮助。
$('.location').off('click').click(function () {
alert($(this).children('a').html());