[英]How to make a button clickabled when hovered over
This question is going to sound strange to many of you.这个问题对你们中的许多人来说听起来很奇怪。 I need a button where it can't be triggered by a click.我需要一个不能通过点击触发的按钮。 That means it won't do an action.这意味着它不会执行任何操作。 Like if the form attribute action
is set to something like next.html
the click won't cause it to go to the next page.就像如果表单属性action
设置为next.html
之类的东西,点击不会导致它转到下一页。
And when the user hovers over the button, it can go to the next site.当用户将鼠标悬停在按钮上时,它可以转到下一个站点。 The reason why I am doing this is because a bot can submit data without hovering over the button .我这样做的原因是因为机器人可以在不将鼠标悬停在按钮上的情况下提交数据。 I am hoping this will prevent bots from submitting anything into my site.我希望这会阻止机器人向我的网站提交任何内容。
I don't really have any code, but is there any way to do this in Javascript/jQuery?我真的没有任何代码,但是有什么方法可以在 Javascript/jQuery 中做到这一点吗?
If this confusing please ask more questions in the comments and I will try to answer to the best of my capabilities.如果这令人困惑,请在评论中提出更多问题,我会尽力回答。
<form>
element机器人搜索<form>
元素action
value机器人查询表单的action
值Bots won't follow your form action
if there's no form in your page.如果您的页面中没有表单,机器人将不会跟随您的表单action
。 If that might sound strange:如果这听起来很奇怪:
Either way (specially if you care about noJS visitors) you need to validate your form无论哪种方式(特别是如果您关心 noJS 访问者),您都需要验证您的表单
Why your hover
approach/intent is bad:为什么你的hover
方法/意图不好:
Now I am not sure how effective this technique would be at blocking bots.现在我不确定这种技术在阻止机器人方面的效果如何。 If you still want to give it a go, I'd do something like this:如果你仍然想试一试,我会做这样的事情:
HTML: HTML:
<form class="form" action="1.php" type="post">
<input type="text">
<input class="submitbutton" type="submit">
</form>
Javascript/jQuery: Javascript/jQuery:
var $form = $('.form'),
$btn = $('.submitbutton');
// Disable submit button on page load
$btn.prop('disabled',true);
// Reactivate submit button on form hover
$form.hover(
function(e){
e.stopPropagation();
$btn.prop('disabled',false);
}, function(e){
e.stopPropagation();
$btn.prop('disabled',true);
}
);
I put together an example at JSFiddle.我在 JSFiddle 上放了一个例子。
In general, clicking the button should submit the form.通常,单击按钮应提交表单。 If you want to force the issue, I think you should try to disable the button first.如果你想强制这个问题,我认为你应该先尝试禁用按钮。
<span style="padding: 8px; background: red;" onmouseout="this.firstChild.disabled='';"><input type="button" name="test" id="test" value="roll over me" onmouseover="this.disabled=true;"></span>
as provided in the answer here:如此处的答案中所述:
Javascript: enable/disable button with mouseover/mouseout Javascript:启用/禁用鼠标悬停/鼠标移出按钮
it seems your question is navigating to another page without clicking a button.您的问题似乎是在不单击按钮的情况下导航到另一个页面。
<html>
<head>
</head>
<body>
<button onmouseover="go()" id="button">hii</button>
<script>
var anchor=document.createElement("a");
var button=document.getElementById("button");
anchor.href="alarm2.html";
function go()
{
button.onmouseover= anchor.click();
}
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.