我试图修改一个触发事件的jQuery,无论是: a)单击搜索文本输入字段,还是b)单击搜索按钮
当单击普通按钮类时,如何更改下面的代码以触发事件?
$( 'form[role=search] input, form[role=search] button' ).on( 'focus, click', function( event ) {我的按钮类是“.搜索-切换”,我尝试将上面的代码替换为:$(".search-toggle").click(function( event ) {,但这是行不通的。
下面是我想要瞄准的按钮的一个粗略片段。
.search-toggle {
background-color: #028A0F;
color: white;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ul>
<li style="float:right">
<button type="button" class="search-toggle">Search</button>
</li>
</ul>
</body>
</html>
发布于 2020-05-24 09:24:24
它应该可以工作,但是您包括了JQuery库吗?你的密码是对的:
$(".search-toggle").click((e) => {
// put here your code
});不过,我建议在按钮上添加属性'onClick‘,然后检查函数是否已被调用,如果没有,请检查它可单击的按钮以及它正在运行的任何元素。
https://stackoverflow.com/questions/61981824
复制相似问题