Javascript 停止输入键以单击按钮
我已经尝试了很多方法,我不知道我现在错过了什么Javascript 停止输入键以单击按钮,javascript,jquery,Javascript,Jquery,我已经尝试了很多方法,我不知道我现在错过了什么 <input id="stopBuy" class="grn" type="button" onclick="selectGT()" value="Buy Now"> 当我们在按钮上单击一次,若鼠标在按钮上方,然后按enter键,则再次单击该按钮时,会出现此问题。所以我想知道是否有办法阻止这一切 我试着把这个放在整个容器里,但不起作用。我已经包括了jqueryv1.8.3 <script> $('#container').
<input id="stopBuy" class="grn" type="button" onclick="selectGT()" value="Buy Now">
当我们在按钮上单击一次,若鼠标在按钮上方,然后按enter键,则再次单击该按钮时,会出现此问题。所以我想知道是否有办法阻止这一切
我试着把这个放在整个容器里,但不起作用。我已经包括了jqueryv1.8.3
<script>
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
}
});
</script>
尝试将代码放入DOM就绪$document.readyfunction{}中;或$function{}使其工作:
$(document).ready(function() {
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
}
});
});
尝试将代码放入DOM就绪$document.readyfunction{}中;或$function{}使其工作:
$(document).ready(function() {
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
}
});
});
也许如果你停止事件传播
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
e.stopPropagation();
}
});
也许如果你停止事件传播
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
e.stopPropagation();
}
});
单击按钮后使其模糊:
$('#stopBuy').click( function() {
$(this).blur();
});
单击按钮后使其模糊:
$('#stopBuy').click( function() {
$(this).blur();
});
var key=e.which | e.keyCode;ifkey===13{$document.readyfunction{};这已经解决了,非常感谢。不确定它是否在所有浏览器中都能工作。但我会检查一下,谢谢@Felix@Allison是的。它可以在所有现有的浏览器中使用。这可以在所有浏览器中使用。可能在IE@allisonvar key=e.which | | e.keyCode;ifkey==13{$document.readyfunction{}的旧版本中使用;非常感谢。不确定它是否能在所有浏览器中运行。但我会检查谢谢@Felix@Allison是的。它可以在所有现有的浏览器中使用。这可以在所有浏览器中使用,可能是在IE@allison的旧版本中