如何获得第二个tbody的id?

时间:2018-04-20 11:10:14

标签: html html-table

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.bind(getSnapshot(position));
    holder.myCustomTextListener.updatePosition(holder.getAdapterPosition());
}

static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

//<shortened, removed various @bindview's...>
    public MyCustomTextListener myCustomTextListener;

    public ViewHolder(View itemView, MyCustomTextListener myCustomTextListener) {
        super(itemView);
        ButterKnife.bind(this, itemView);

        this.myCustomTextListener = myCustomTextListener;
        this.quantity.addTextChangedListener(myCustomTextListener);
    }

public void bind(final DocumentSnapshot snapshot) {
 AddOrderProductList orders = snapshot.toObject(AddOrderProductList.class);
 //<shortened, various setText's here...>
}

private class MyCustomTextListener implements TextWatcher {
    private int position;

    public void updatePosition(int position) {
        this.position = position;
    }

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        Log.d(TAG, "onTextChanged at " + position + " with this CharSequence: " + charSequence);
    }

    @Override
    public void afterTextChanged(Editable editable) {
        Log.d(TAG,  "afterTextChanged at " + position);
    }
}

对于第一个是bindNotification的tbody,我可以使用<table id="notificationTable"> <tbody id="bindNotification"> <tr> <td> <table> <tbody id="titleNotification" style="position:fixed; margin-top:-4px; margin-left:-3px;"> </table> </td> </tr> </tbody> </table> 获取id

但是对于第二个作为titleNotification的tbody,我使用相同的方法来获取id但它的null。 有没有其他方法来检索ID?

1 个答案:

答案 0 :(得分:1)

let x = document.getElementById("titleNotification");
alert(x);
<table id="notificationTable">
  <tbody id="bindNotification">
    <tr>
      <td>
        <table>
          <tbody id="titleNotification" style="position:fixed; margin-top:-4px; margin-left:-3px;">
          </tbody>
        </table>
      </td>
    </tr>
  </tbody>
</table>