问题:
我正在尝试通过按钮实现下拉表单。但是,即使满足条件,我也遇到了表单不可见的问题。我是 javascript 和 css 的新手,如果这是一个愚蠢的错误,请多多包涵。提前致谢。
我想做什么:
- The form will be hidden by default.
- When a user hovers over an image button, the form should be shown and hidden after the mouseleave.
- If the user clicks the button, then the form should stay visible so that the user can enter the data and sumbit it.
观察:
- The objectives #1 and #2 from above are working as expected.
- As opposed to objective #3, the form automatically hides even after the button click.
不成功的方法:
- Using
.show()
instead of.css("display","block")
- Using
form:hover
to setdisplay:block
.- Using
setTimeout(hide_function,500)
hides the form after 500ms regardless of the button click.
代码:
这是我的 jsfiddle 的链接您可以用来测试它。
引用资料:
最佳答案
只需更改数据属性:
$('#dropbtn').click(function() {
$(this).data('clicked', 'yes');
$('#loginForm').css('display', 'block');
});
关于javascript - 单击按钮后无法显示表单元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45711399/