function siradaki() {
var high = Math.max.apply(Math, $('.sira').map(function() {
return $(this).text()
}))
alert(high);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<table id="myTable">
<tr class="header">
<th style="width:10%;">Name</th>
<th style="width:10%;">Lastname</th>
<th style="width:10%;">Value</th>
</tr>
<tr>
<td>Deneme</td>
<td>SDeneme</td>
<td class="sira">100</td>
</tr>
<tr>
<td>Ornek</td>
<td>SOrnek</td>
<td class="sira">150</td>
</tr>
</table>
<button name="siradaki" id="siradaki" class="btn btn-warning" onclick="siradaki();">Sıradaki Kim ?</button>
此代码有效。但是如何获得Name
和Lastname
以及最大Value
呢?
答案 0 :(得分:1)
获取所有行,而不仅仅是.sira
单元格中的值,然后对其进行分析。这样,当您找到最大数量时,您将拥有完整的信息。
function siradaki() {
var max = -Infinity;
var maxRow;
$('tbody tr').each(function() {
var value = parseInt($('.sira', this).text(), 10);
if (value > max) {
max = value;
maxRow = $(this);
}
});
alert(maxRow.text());
}
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<table id="myTable">
<thead>
<tr class="header">
<th style="width:10%;">Name</th>
<th style="width:10%;">Lastname</th>
<th style="width:10%;">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Deneme</td>
<td>SDeneme</td>
<td class="sira">100</td>
</tr>
<tr>
<td>Ornek</td>
<td>SOrnek</td>
<td class="sira">150</td>
</tr>
</tbody>
</table>
<button name="siradaki" id="siradaki" class="btn btn-warning" onclick="siradaki();">Sıradaki Kim ?</button>
</html>
答案 1 :(得分:1)
您可以使用rowRDD.foreachPartition(new VoidFunction<Iterator<String () {
private static final long serialVersionUID = 1L;
@Override
public void call(Iterator<String> rowIterator) throws Exception {
//prepared statement query
String sql = "insert into " + tableName + " (TRANS_AMOUNT,) values (?, ?)";
Connection connection = null;
PreparedStatement ps = null;
try {
connection = DriverManager.getConnection(jdbcDatabaseUrl, jdbcUsername, jdbcPassword);
ps = connection.prepareStatement(sql);
int count = 0;
RowTemplate message = new RowTemplate();
while (rowIterator.hasNext() ) {
String recordRow = rowIterator.next();
if (recordRow != null && !recordRow.equals("")) {
//populate message object properties
message.setProperties(recordRow,kafkaRecorddelimiter);
java.util.Date transDate = formatter.parse(trnsDateTime);
Timestamp transactionDate = new Timestamp(transDate.getTime());
String transAmount = message.getTransactionAmount() ;
ps.setInt(1, Integer.parseInt(transAmount);
ps.setTimestamp(2, transactionDate);
ps.addBatch();
if(++count % batchSize == 0)
ps.executeBatch();
}
message.clearProperties();
}
ps.executeBatch(); // insert remaining records
}
获取同级.siblings
元素,并使用td
获取其文本。将它们存储在字符串中,并以高警惕
.textContent
var str='';
function siradaki(){
var high = Math.max.apply(Math, $('tr > .sira').map(function(){
var a=Object.values($(this).siblings())
str=a[0].textContent+ " " + a[1].textContent;
return $(this).text();
}))
alert (str + " " +high );
}
答案 2 :(得分:0)
function siradaki(){
var value = $('tr td').map(function () {
return parseInt($(this).text(), 10) ? parseInt($(this).text(), 10) : null;
}).get();
var high = Math.max.apply(Math, value);
alert(high);
}
尝试不要添加类来获取所有行
答案 3 :(得分:0)
尝试按desc顺序按值对列表进行排序,并从列表中获取第一个对象
function siradaki() {
var high = $('.sira').sort(function(a, b) {
return $(a).text() < $(b).text()
})[0];
console.log($(high).closest('tr').find('td:eq(0)').text());
console.log($(high).closest('tr').find('td:eq(1)').text());
console.log($(high).text());
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<table id="myTable">
<tr class="header">
<th style="width:10%;">Name</th>
<th style="width:10%;">Lastname</th>
<th style="width:10%;">Value</th>
</tr>
<tr>
<td>Deneme</td>
<td>SDeneme</td>
<td class="sira">100</td>
</tr>
<tr>
<td>Ornek</td>
<td>SOrnek</td>
<td class="sira">150</td>
</tr>
</table>
<button name="siradaki" id="siradaki" class="btn btn-warning" onclick="siradaki();">Sıradaki Kim ?</button>
答案 4 :(得分:0)
您可以尝试这样
function siradaki() {
var arr = [];
$('.sira').each(function() {
arr.push($(this).text());
var Names = $(this).siblings('td').text();
console.log('Names: '+ Names);
})
var maxValue = Math.max.apply(Math, arr);
console.log('maxValue: '+maxValue);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<table id="myTable">
<tr class="header">
<th style="width:10%;">Name</th>
<th style="width:10%;">Lastname</th>
<th style="width:10%;">Value</th>
</tr>
<tr>
<td>Deneme</td>
<td>SDeneme</td>
<td class="sira">100</td>
</tr>
<tr>
<td>Ornek</td>
<td>SOrnek</td>
<td class="sira">150</td>
</tr>
</table>
<button name="siradaki" id="siradaki" class="btn btn-warning" onclick="siradaki();">Sıradaki Kim ?</button>
答案 5 :(得分:0)
只需在这里查看jQuery的同级方法-https://api.jquery.com/siblings/
您可以使用 tr 标记作为参数访问兄弟姐妹,并使用索引来区分名字和姓氏,即0表示姓氏,1表示姓氏。