我有 3 个单选按钮,将根据单击的按钮显示列表中的某些作业。我曾经使用搜索按钮来运行搜索代码。因此,用户将选择一个单选按钮,然后单击搜索。但现在我已经删除了搜索按钮,我希望单选按钮在单击时调用搜索功能。
<table>
<tr>
<td>
<label id="lblAll" runat="server">All</label>
<input type="radio" name="rbl_filter" runat="server" id="rbAll" onclick="btnSearch_Click" />
</td>
<td>
<label id="lblCollections" runat="server">Collections</label>
<input type="radio" name="rbl_filter" runat="server" id="rbCollections" checked="true" onclick="btnSearch_Click"/>
</td>
<td>
<label id="lblDeliveries" runat="server">Deliveries</label>
<input type="radio" name="rbl_filter" runat="server" id="rbDeliveries" onclick="btnSearch_Click" />
</td>
</tr>
</table>
我添加了与搜索按钮使用的相同的 onclick 代码。但是当我单击单选按钮时没有任何反应
最佳答案
你必须在函数名称后使用 ()
这就是你想要的
function btnSearch_Click() {
alert("hello");
}
<table>
<tr>
<td>
<label id="lblAll" runat="server">All</label>
<input type="radio" name="rbl_filter" runat="server" id="rbAll" onclick="btnSearch_Click();" />
</td>
<td>
<label id="lblCollections" runat="server">Collections</label>
<input type="radio" name="rbl_filter" runat="server" id="rbCollections" checked="true" onclick="btnSearch_Click();" />
</td>
<td>
<label id="lblDeliveries" runat="server">Deliveries</label>
<input type="radio" name="rbl_filter" runat="server" id="rbDeliveries" onclick="btnSearch_Click();" />
</td>
</tr>
</table>
以及 jsfiddle
关于javascript - 单选按钮 onclick 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32139849/