简体   繁体   English

怎么获得<td> jquery中带有span类的值

[英]how to get <td> value with span class in jquery

My table is我的桌子是

<table id="ResumeWrite" class="Vasprice" cellpadding="0" cellspacing="0" border="0" width="100%">
 <tr>
       <th width="20%" class="bdrL_blue valignT highlight">
       <span class="font18">0 to 1 year Experience</span>
       </th>

       <th>
        <input type="button" value="submit"/>
       </th>
</tr>

i want to alert the value 0 to 1 year Experience when i click the button.当我单击按钮时,我想提醒值0 to 1 year Experience how to do in jquery?在jquery中怎么做?

$('input[type="button"]')click(function(e){
e.preventDefault();

alert($(".bdrL_blue").text());
});

and you can do by also following way你也可以通过以下方式来做

   $('input[type="button"]').click(function(e){
    e.preventDefault();
        $(this).closest('tr').find('span').text();
       //or
      $(this).closest('tr').find('th').text();
    });

see DEMO by all THREE WAYS通过三种方式查看演示

You can do this by many ways.您可以通过多种方式做到这一点。 I think most simple is:我觉得最简单的是:

$(".font18").text();
$(".font18").html();

or或者

$("#ResumeWrite span.font18").text();

Last string only improves the accuracy of the finding desired item.最后一个字符串只会提高查找所需项目的准确性。

Try this:尝试这个:

$('input[type="button"]').click(function() {
    var text = $(this).closest('tr').find('span').text();
    alert(text);
});

Note, I didn't use the classes on the element to select it as they appear to be style classes, and not semantically linked to the content of the element.请注意,我没有使用元素上的类来选择它,因为它们看起来是样式类,并且在语义上没有链接到元素的内容。

Example fiddle示例小提琴

$('#ResumeWrite input[type="button"]').click(function(){
    alert($(this).parent().prev().find('span').text())
})

Demo: Fiddle演示:小提琴

alert($(".font18").text());

or alert($("#resumeWrite .highlight span").text());或 alert($("#resumeWrite .highlight span").text()); You should read the jquery doc, and follow some tutorial, it's very basic...您应该阅读 jquery 文档,并遵循一些教程,这是非常基本的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM