内の特定のTDの最高値を取得:は私が怒鳴るようなテーブル構造を持つ動的テーブル
function highestPosInBlock(posId) {
// determine the highest number in the current block
console.log($("body").data("block")); // ...
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table data-block="1">
<tr>
<td data-position="1">1</td>
</tr>
<tr>
<td data-position="2">2</td>
</tr>
<tr>
<td data-position="3">3</td>
</tr>
</table>
<table data-block="2">
<tr>
<td data-position="1">1</td>
</tr>
<tr>
<td data-position="2">2</td>
</tr>
</table>
私は与えられたブロックの最高data-position
属性を取得します。これまでのJS関数は次のようになります。
function highestPosInBlock(posId) {
// determine the highest number in the current block
console.log($("body").data("block") // ...
}
これは私が立ち往生した場所です。私が渡す引数は与えられたデータブロックです。それは2
任意のアイデアどのようにそれを行うに戻りshoudl私はここで3
私は呼びたいhighestPosInBlock(2)
を取得したい
highestPosInBlock(1)
:たとえば、私はこのような関数を呼び出すと思いますか?私は完全なブラックアウトをしています。
もう一つ:このたわごとはIE 7で動作するように持っているので、私は、jQueryの各-イテレータを使用することはできません、(それぞれをサポートしていません)
最初にあなたが望むテーブルを取得する:$( 'table [data-block = "1"]') 'それから[find](https://api.jquery.com/find/) ](https://api.jquery.com/each/)それらの、[データの位置を取得する](http://stackoverflow.com/questions/5309926/how-to-get-the-data-id-属性)および[最大値を追跡する(http://stackoverflow.com/questions/28767330/javascript-biggest-number-from-array-using-loop) – musefan
@DasSaffe)が(使用各々を防止するために、ループのために添加しましたあなたがあなたの質問で言ったように –