添加样式类时输入按钮不再起作用

问题描述 投票:0回答:1

$(document).ready(function(){
  $(".button2").click(function(){
    alert("clicked")
  });
});
[type='button'].button2 {
    background: white;
    color: black;
    margin-left: 31%;
    font-weight: bold;
 }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="https://google.com">
 <input type="button" class="button2" value="Start Browsing!" />
 </form>

当我添加一个类时,我的按钮不再可单击。我该如何解决?谢谢!

HTML

`<form action="https://google.com">
 <input type="button" class="button2" value="Start Browsing!" />
 </form>`

CSS

`[type='button'].button2 {
    background: white;
    color: black;
    margin-left: 31%;
    font-weight: bold;
 }`

我尝试添加“div”而不是类,但这也不起作用。

我正在使用的页面上还有另一个按钮

“不可点击”是什么意思?我尝试添加 JavaScript 函数,它显示按钮单击操作仍在被调用,如下所示:

CSS

<style>
[type='button'].button2 {
    background: white;
    color: black;
    margin-left: 31%;
    font-weight: bold;
 }
</style>

带有 JS 函数的 HTML

<input type="button" class="button2" value="Start Browsing!" onclick="alert('click button')" />

如果您尝试了上面的代码,实际上按钮已经被单击并显示警报。

如果您的意思是“不可点击”是按钮标准悬停效果,您可以使用下面的 CSS 来实现按钮悬停效果

<style>
[type='button'].button2 {
    background: white;
    color: black;
    margin-left: 31%;
    font-weight: bold;
    cursor: pointer;
 }
 
 [type='button'].button2:hover{
    background: #E7E7E7
 }
 
</style>

希望对你有帮助:)

html css class button input
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.