![](/img/trans.png)
[英]Jquery - On input, Get the value of a span inside a td using span class
[英]how to get <td> value with span class in jquery
我的桌子是
<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>
当我单击按钮时,我想提醒值0 to 1 year Experience
。 在jquery中怎么做?
$('input[type="button"]')click(function(e){
e.preventDefault();
alert($(".bdrL_blue").text());
});
你也可以通过以下方式来做
$('input[type="button"]').click(function(e){
e.preventDefault();
$(this).closest('tr').find('span').text();
//or
$(this).closest('tr').find('th').text();
});
您可以通过多种方式做到这一点。 我觉得最简单的是:
$(".font18").text();
$(".font18").html();
或者
$("#ResumeWrite span.font18").text();
最后一个字符串只会提高查找所需项目的准确性。
尝试这个:
$('input[type="button"]').click(function() {
var text = $(this).closest('tr').find('span').text();
alert(text);
});
请注意,我没有使用元素上的类来选择它,因为它们看起来是样式类,并且在语义上没有链接到元素的内容。
$('#ResumeWrite input[type="button"]').click(function(){
alert($(this).parent().prev().find('span').text())
})
演示:小提琴
alert($(".font18").text());
或 alert($("#resumeWrite .highlight span").text()); 您应该阅读 jquery 文档,并遵循一些教程,这是非常基本的...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.