我正在尝试使用 Javascript 单击下面的选择。
<div class="CRControllerAddButton">
<u colspan="2">Add Access Time</u>
</div>
我正在尝试使用document.getElementById('CRControllerAddButton').click();
我怎么不能让它工作?是因为它是一个类吗?我只需要点击 div 就可以了。
让我们说 chrome 上的控制台可以使用什么 javascript 来执行此操作?
如果需要,下面是整个代码的嵌套位置。
<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="<<" style="display: none;">
<input type="button" class="inputbutton" value="<" style="display: none;">
<input type="button" class="inputbutton" value="OK">
<input type="button" class="inputbutton" value="Cancel">
<input type="button" class="inputbutton" value=">" style="display: none;">
<input type="button" class="inputbutton" value=">>" style="display: none;">
</div>
</div>