检查特定的id元素是否存在

时间:2019-01-03 08:58:56

标签: javascript jquery

我想检查特定的id元素是否存在。对于前。 id =“ tbvAccountProc:frmFinancingDocumentProcess:btnSave”在这里,我想检查btnSave是否存在。

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.process_text_main);
    CharSequence text = getIntent()
      .getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
    // process the text
}

if ($('#btnSave').length) {
    }

if ($('#btnSave').length > 0) {
}

if ($('#frmFinancingDocumentProcess').length) {
}

尝试了这些,但是视图中存在btnSave,但是它们没有按我预期的那样工作。

如果我检查btnSave是否存在,它必须为return alert('true')否则为false。

HTML:

if (document.getElementById('btnSave')) {
}

0 个答案:

没有答案