- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
html 是
<table>
<tr>
<td><img src="ex.jpg" id="image" class="edit" name="n1"></td>
<td><img src="ex.jpg" id="image" class="edit" name="n2"></td>
<td><img src="ex.jpg" id="image" class="edit" name="n3"></td>
<td><img src="ex.jpg" id="image" class="edit" name="n4"></td>
</tr>
</table>
Jquery 代码是:
$(".edit").click(function() {
$("#image").each(function(){
alert(this.name);
});
});
这里,它只提醒一个名字,我的意思是只提醒“n1”。
我如何提醒名称属性。每个元素?
谢谢
最佳答案
多个元素不能具有相同的 ID(因此得名:ID)。如果这样做,#image
始终仅匹配具有给定 ID 的第一个元素(在您的情况下为 #n1 图像)。但是,您可以向一个元素添加多个类:
HTML:
<img class="edit image" name="foobar" />
JS:
$(".image").each(function(){
alert($(this).attr('name'));
});
在此上下文中的
this
是普通 DOM 元素。您首先必须将其更改为 jQuery 对象 (var $that = $(this)
),然后才能对其使用 .attr()
。
关于jquery - 如何使用jquery的每个函数来获取每个元素的attr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1686009/
我只是想知道下面的$(*[attr])和$([attr])中哪一个更可取。为什么? 因为两者都在做同样的事情。 $('[onclick]').each(function(i,elem){ cons
长期以来我一直在尝试找出问题所在,但不幸的是无法 如果我这样做 android.enableAapt2=true 代码工作正常,但是删除相同的(应该是强制性的)会抛出一个错误说 \incrementa
使用此代码: $('#ipadmenu section').attr('data-order', hash) 我将 data-order 属性设置为“hash”的值。如何选择具有该属性/值的元素而不是
我有一个用于扩展的组合框监听器。展开后,它会对组合框选项中具有特定类的每个元素执行一些样式设置。所需的更改之一是根据当前属性的值更改属性。使用 this 返回未定义。 expand : funct
性能上有区别吗 :not([attr="value"]) 和 [attr!="value"] ? CSS3 规范是否推荐了一种替代方案? 编辑: CSS3 规范不包含 [attr!="value"]
所以我有一个叫做 say,mySave 的指令,它几乎就是这个 app.directive('mySave', function($http) { return function(scope,
有人可以告诉我有什么区别吗 ?android:attr/colorPrimary 和 ?attr/colorPrimary 无论我使用哪个,结果都是一样的。尽管第一个选项导致android.view.
Xpath问题: 何时使用@和属性,何时不使用。有关系吗?有什么区别 最佳答案 使用//tag[attr]时,将选择所有具有至少一个名为tag的子元素的attr元素。另一方面,使用//tag[@att
android布局xml文件中的?android:attr/和?attr/有什么区别?在不同的情况下我们应该使用哪一个? 最佳答案 1。 ?attr/ 定义并引用您在应用程序中自行定义的属性的值。 2
如果 obj 不存在 obj? 生成一个 nil 所以 obj?.attr 也是。 如果 obj 为 nil,则 obj!.attr 崩溃。 但是如果我确定 obj 在代码的某个点总是存在,那么对我来
有一个这样的 HTML。 Back 1 2 3 Next 为了获得最大的页数,我写了这篇文章。 doc = Nokogiri::HTML(html) doc.xpath('//
我想知道这些标签在 android xml 中如何工作。例如在造型方面 style="?android:attr/buttonBarButtonStyle" 和 style="@android:att
这是我的代码: $("input[name=donationmode]").change(function() { $(".setpaymentOptions").children().add
我已经搜索了一段时间,但没有找到我正在搜索的内容。 事情是这样的,我有两张表,我们称它们为表 A 和 B。当 A 更新时,我需要更新 B 中的属性。例如:A. 电子邮件和 B. 电子邮件。当用户在 A
大家好,在访问一个循环的 php 变量时遇到了一个小问题。我的脚本循环使用来自 mysql 数据库的 x 和 y。它还循环出我无法访问的 id,它显示为未定义。我正在使用鼠标移开功能来检测已循环的每个
我将自己的标签转换为输入。我可以使用 select 为输入选择只读/禁用。我做到了。有用。但不是在 ie8 )). 我阅读了 Angular 和 IE8 的官方文档。我添加了它。但是我的应用程序在 i
我正在使用令人惊叹的 attrs 库以一种非常优雅的方式定义许多对象属性,到目前为止它一直运行得非常棒。 我目前遇到的唯一问题是,有时我想通过引用其他 attr.ib() 属性来定义默认值。如果 na
我注意到 javascript 有几种方法来设置和获取元素的属性。 我不确定它们之间有什么区别。特别是,是否存在跨浏览器问题。 最佳答案 DOM 元素的特性和属性有很大不同,这种差异是一些混淆的根源。
在 4.x 设备上,使用 ?android:attr/selectableItemBackgroundBorderless 的布局文件会导致崩溃,但 ?attr/selectableItemBackg
.attr('disabled', 'disabled') 和 .attr('disabled', true) 在我的代码中都有效,但我只是想知道:两者中哪一个更有效和/或哪一个更常用?真的有区别吗?
我是一名优秀的程序员,十分优秀!