[英]Get Element with Mootools css selector for same element with same id
I have a table which has several links in td tag with the same id,can I get the link's inner html respectively.I want to know 我有一个表在td标签中有几个具有相同id的链接,我可以分别得到链接的内部html。我想知道
the is what I want - 这就是我想要的 -
<table>
<tr>
<td> <a href="javascript:void(0)" class="update_room_link">Edit</a>
</td>
<td> <a href="javascript:void(0)" class="update_room_link">Delete</a>
</td>
<td> <a href="javascript:void(0)" class="update_room_link">Add</a>
</td>
</tr>
</table>
javascript tried as javascript试过
$$('#update_room_link').addEvent('click', function () {
alert();// get innerHtml of Edit,Delete or Add as clicked
})
Questions updated 问题已更新
I have a html SELECT in a table row,this row has many table data.I want to get the value/innerhtml of a table data which has its id set (and within the SAME row).Or how can I get an immediate grand-parent of a child FROM a child..is it possible 我在表行中有一个html SELECT,这行有很多表数据。我想得到一个表数据的值/ innerhtml,它的id设置(并在SAME行中)。或者我怎么能得到一个直接的盛大 - 孩子的父母 - 孩子......这是可能的
<tr>
<td id="id">100</td>
<td>Australi</td>
<td>BAT</td>
<td>2014-02-23</td>
<td>pending</td>
</tr>
I want the innerhtml of name of the SELECTED option. 我想要SELECTED选项的名称的innerhtml。 All the select has same class name.
所有选择都具有相同的类名。
The ID must be unique in a html element, that's why you can not use the same ids on your a
tags so $$('#update_room_link')
is for all elements. ID必须在html元素中是唯一的,这就是为什么你不能在你
a
标签上使用相同的id,所以$$('#update_room_link')
适用于所有元素。
You can use the class and can get inner html like this 你可以使用这个类,并可以获得这样的内部HTML
$$('.update_room_link').addEvent('click', function () {
alert(this.innerHTML); //here you will get the respective inner HTML
})
Please see ID shold be unique 请参阅ID shold是独一无二的
If you want use id then it should be unique, in that case you will have to attach each function independntly, which is not good practice, like 如果你想使用id那么它应该是唯一的,在这种情况下你必须独立地附加每个函数,这不是好习惯,比如
$$('#update_room_link1').addEvent('click', function () {....
$$('#update_room_link2').addEvent('click', function () {....
I add this answer after you already accepted a answer, just to complete a bit. 我已经接受了答案之后添加了这个答案,只是为了完成一点。
If you want to add event to one element by ID you can use 如果您想通过ID向一个元素添加事件,则可以使用
$('update_room_link').addEvent('click', function () {
it will also work with 它也可以使用
$$('#update_room_link').addEvent('click', function () {
To add events to many elements, by CLASS you can use 要向多个元素添加事件,可以使用CLASS
$$('.update_room_link').addEvent('click', function () {
To get the HTML the recommended method by MooTools is 要获得HTML ,MooTools推荐的方法是
element.get('html');
but will also work with 但也会合作
element.innerHTML
since mootools uses native elements 因为mootools使用原生元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.