用于href中元素的jquery选择器

jquery selector for element within a href

本文关键字:jquery 选择器 元素 href 用于      更新时间:2024-05-21

如何使用Jquery选择器获取"name"中的文本(id)?

<a href="page1.php" id='title' name="<?php echo $res['id'];?>" title="<?php echo $res['title'];?>"  <?php echo $res['sku'];?></a>

我试过了:

$('#title name ').text();

您可以使用.attr():

$('#title').attr('name');

你试过吗?

$('#title').attr('name');

您尝试的选择器:

$('#title name').text();

意味着您正在尝试检索元素标记name(在HTML中不存在)的文本,该标记是具有id标题的元素的子级。