English 中文(简体)
从表格中收集数据
原标题:Collecting data with jQuery from a table

我有一个这样的表:

<table>
    <thead>
       <tr>
           <th></th>
           <th>Name</th>
           <th>Email</th>
       </tr>
    </thead>
    <tbody>
        <tr>
            <td class= checkinput >
                <input type="checkbox" name="names" value="MD5_HASH"/>
            </td>
            <td>
                John Doe
            </td>
            <td>
                email@mail.com
            </td>
        </tr>
        <!-- etc. -->
    </tbody>
</table>

Essentially, I m trying to build an application where you can select each row in the table that you want, then export the emails to a comma-delimited list. The problem I m having is how to traverse the table and grab the information I need.

目前,为了方便起见,我已做以下工作,以便每行在点击时把检查箱捆绑起来。 不幸的是,当查箱直接点击时,没有发生任何事情,因为它试图在叫作Java文本时盘点自己,将其送回:

$("tr").click(function() {
    var $checkbox = $(this).find(":checkbox");
    $checkbox.attr( checked , !$checkbox.attr( checked ));
});

我如何能够优化这一努力,使它能够点击投入本身,而不是发生这场冲突?

而且,当我最后准备提交时,我如何从选择<代码><input>的每行转和阅读电子邮件?

最佳回答

[Edited to correct error in first part due to misunderstanding]

www.un.org/Depts/DGACM/index_spanish.htm 为了防止不受欢迎的检查箱行为,如果点击直接放在检查箱上,就离开你的手稿:

$("tr").click(function(e) {
    if ($(e.target).is( :checkbox )) return;
    var $checkbox = $(this).find(":checkbox");
    $checkbox.attr( checked , !$checkbox.attr( checked ));
});

如果事件源自检查箱,我们就让检查箱履行违约行为。 学习参考资料

www.un.org/Depts/DGACM/index_spanish.htm 为了在经过核对的行文上收发电子邮件,您应考虑在<代码>上设置}=“email>>;td>,使改动更加方便。 之后,使用这样的东西:

var emails = [];
$("table tbody tr:has(input:checkbox:checked)").each(function(){
   emails.push( $( td.email , $(this)).text() );
});

请注意,你可能希望破碎,在开始和结束的时候消除不受欢迎的白人空间。

了解使用的选用器(:check Box ,:checked and :has)

问题回答

在职能范围内进行第一次问答:

$("tr).click(function(e) {
if (e.target.id==xxx)      //  if ($( # +e.target.id).attr( class )== classssss ) ...
....


});

如果检查箱有(或班级更好)是检查箱,如果是的话。

关于第二个问题:

$(".table tr:gt(0)").each (

function () {

alert($( td:eq(2) ,$(this)).text());

}
);




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!