<table class="table" align="center" id="tblMain">
<tr>
<td>Status</td>
<td><b><span name="current" value="Dispatch">Dispatch</span></b></td>
</tr>
</table>
JS
$('#tblMain').find('td').ready(function()
if( $('#current').val() == 'Dispatch')
{
alert('Dispatch');
}
else
{
alert('Nothing found');
}
);
I need table cell value to compare with with my status and should alert as given ..how to achieve this?
我需要表格单元格值与我的状态进行比较,并应该提醒..如何实现这一点?
2 个解决方案
#1
3
-
<span>
don't havevalue
attribute, so it is invalid HTML. Use customdata-*
attributes. -
current
is thename
of element, notid
. Useattribute selector
to select element by an attribute. -
ready
should be called ondocument
没有value属性,因此它是无效的HTML。使用自定义data- *属性。
current是元素的名称,而不是id。使用属性选择器按属性选择元素。
准备应该在文件上调用
$(document).ready(function() {
if ($('span[name="current"]').data('value') == 'Dispatch') {
alert('Dispatch');
} else {
alert('Nothing found');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<span name="current" data-value="Dispatch">Dispatch</span>
<!-- ^^^^^^^^^^^^^^^^^^^^^^ -->
#2
-1
$(".table").find("tr td:nth-child(1)").text();
#1
3
-
<span>
don't havevalue
attribute, so it is invalid HTML. Use customdata-*
attributes. -
current
is thename
of element, notid
. Useattribute selector
to select element by an attribute. -
ready
should be called ondocument
没有value属性,因此它是无效的HTML。使用自定义data- *属性。
current是元素的名称,而不是id。使用属性选择器按属性选择元素。
准备应该在文件上调用
$(document).ready(function() {
if ($('span[name="current"]').data('value') == 'Dispatch') {
alert('Dispatch');
} else {
alert('Nothing found');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<span name="current" data-value="Dispatch">Dispatch</span>
<!-- ^^^^^^^^^^^^^^^^^^^^^^ -->
#2
-1
$(".table").find("tr td:nth-child(1)").text();