我需要使用jquery逐步计算。我有一张桌子,一个td是这样的:
<td class="number"></td>
我在jquery官方网站上看到这段代码
$( "li" ).each(function( index ) {
console.log( index + ": " + $( this ).text() );
});
我尝试了这样的代码
$( ".number" ).each(function( index ) {
var num = ( index)+1;
});
$(".number").text(num)
但不会做任何事情
答案 0 :(得分:0)
private void addDrawerItems() {
String[] osArray = { "Android", "black" };
//create also an array of paths to html files
final String[] pathsArray = { "file:///android_asset/www/help.html", "HERE_MUST_BE_ANOTHER_PATH_TO_ANOTHER_FILE" };
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Time for an upgrade!", Toast.LENGTH_SHORT).show();
//load file to webView from pathsArray
// getting current path from arg. position
mWebView.loadUrl(pathsArray[position]);
//close drawer
mDrawerLayout.closeDrawers();
}
});
}
答案 1 :(得分:0)
您的问题并不是很明显,但如果您想将每个td的编号放在其中,请使用以下代码:
$('.number').each(function(index){
$(this).html(index + 1);
});
循环内的$(this)
指向循环中的当前td ...