我可以使用javascript单击此选择吗?

我可以使用javascript单击此选择吗?,javascript,html,Javascript,Html,我正在尝试使用Javascript单击下面的选择 <div class="CRControllerAddButton"> <u colspan="2">Add Access Time</u> </div> 是的,这是因为它是一个类,而不是id。但是有一个函数可以获取具有给定类的所有元素: 使用 这里有一个[0],因为可以有多个元素,所以此函数返回一个活动节点列表,其工作原理类似于数组 如果你想点击所有有这个类的元素,在由getElemen

我正在尝试使用Javascript单击下面的选择

<div class="CRControllerAddButton">
    <u colspan="2">Add Access Time</u>
</div>

是的,这是因为它是一个类,而不是id。但是有一个函数可以获取具有给定类的所有元素:

使用

这里有一个
[0]
,因为可以有多个元素,所以此函数返回一个活动节点列表,其工作原理类似于数组


如果你想点击所有有这个类的元素,在由
getElementsByClassName

Nada返回的活动节点列表上循环,它会给我一个错误
TypeError:Object#没有方法“getElementByClassName”
它没有选择正确的链接,它打开了其他什么?知道吗?它打开了一个我已经命名的按钮。我怎么能特别选择这个呢?在你展示的HTML中,这个类的元素不是链接。不管怎样,我得到了它!它的
document.getElementsByCassName('CRControllerAddButton')[4]。单击()没有与“CRControllerAddButton”匹配的
id
,因此您尝试单击
未定义的
 <div id="CRbodyaccesspolicyid" layer="0" class="CRController_body" style="width: 360px; top: 444px; left: 469px;">
  <div style="width:100%;background:#FFF;" align="center">
    <input type="text" class="CRsearchtext" id="CRSearchTextaccesspolicyid">
  </div>
  <div id="CRControllerDataaccesspolicyid" style="overflow: auto; height: 61px;">
    <table style="width: 100%;">
      <tbody>
        <tr>
          <td colspan="2"><div class="CRControllerAddButton"><u colspan="2">Add Access Time</u></div></td>
        </tr>
        <tr>
          <td title="Allowed all the time" style="width: 50%;"><input type="radio" id="chkaccesspolicyid_1" name="radioaccesspolicyid" key="1" label="Allowed all the time" style="float: left;">
            <div style="overflow: hidden; width: 134px; white-space: nowrap; padding-top: 2px; text-overflow: ellipsis;">Allowed all the time</div></td>
          <td title="Denied all the time" style="width: 50%;"><input type="radio" id="chkaccesspolicyid_2" name="radioaccesspolicyid" key="2" label="Denied all the time" style="float: left;">
            <div style="overflow: hidden; width: 134px; white-space: nowrap; padding-top: 2px; text-overflow: ellipsis;">Denied all the time</div></td>
        </tr>
        <tr>
          <td title="Allowed only during Work Hours" style="width: 50%;"><input type="radio" id="chkaccesspolicyid_3" name="radioaccesspolicyid" key="3" label="Allowed only during Work Hours" style="float: left;">
            <div style="overflow: hidden; width: 134px; white-space: nowrap; padding-top: 2px; text-overflow: ellipsis;">Allowed only during Work Hours</div></td>
          <td title="Denied during Work  hours" style="width: 50%;"><input type="radio" id="chkaccesspolicyid_4" name="radioaccesspolicyid" key="4" label="Denied during Work  hours" style="float: left;">
            <div style="overflow: hidden; width: 134px; white-space: nowrap; padding-top: 2px; text-overflow: ellipsis;">Denied during Work  hours</div></td>
          <td></td>
        </tr>
      </tbody>
    </table>
  </div>
  <div id="CRControllerButtonaccesspolicyid" align="center">
    <input type="button" class="inputbutton" value="&lt;&lt;" style="display: none;">
    <input type="button" class="inputbutton" value="&lt;" style="display: none;">
    <input type="button" class="inputbutton" value="OK">
    <input type="button" class="inputbutton" value="Cancel">
    <input type="button" class="inputbutton" value="&gt;" style="display: none;">
    <input type="button" class="inputbutton" value="&gt;&gt;" style="display: none;">
  </div>
</div>
document.getElementsByClassName('CRControllerAddButton')[0].click();