jQuery 四四方方的问题
我使用 jquery boxy 来调用我的验证码覆盖:
<script>
$(document).ready(function() {
var zahl1 = Math.floor(Math.random()*11);
var zahl2 = Math.floor(Math.random()*31);
//$("#cap").html("Wie viel ist "+zahl1+" + "+zahl2+"? <input type='text' id='answer' />");
$("#shortbutton").live("click", function() {
ask();
return false;
});
});
function ask()
{
zahl1 = Math.floor(Math.random()*11);
zahl2 = Math.floor(Math.random()*31);
var sum = zahl1 + zahl2;
new Boxy.ask("Wie viel ist "+zahl1+" + "+zahl2+"? <input type='text' id='answ' />",
["Ok"],
function(val) {
if($("#answ").val() == (zahl1 + zahl2))
{
$("#form").submit();
}
else
{
ask();
return false;
}
},
{title: "Captcha"}
);
}
</script>
代码有点不干净...函数称它们为 selfts...我知道...但是我怎样才能在 Enter Press 上调用“OK”事件...
所以你写下答案并按 Enter 键...然后它就会检查。
有什么想法吗?
i using a jquery boxy to call my captche overlay:
<script>
$(document).ready(function() {
var zahl1 = Math.floor(Math.random()*11);
var zahl2 = Math.floor(Math.random()*31);
//$("#cap").html("Wie viel ist "+zahl1+" + "+zahl2+"? <input type='text' id='answer' />");
$("#shortbutton").live("click", function() {
ask();
return false;
});
});
function ask()
{
zahl1 = Math.floor(Math.random()*11);
zahl2 = Math.floor(Math.random()*31);
var sum = zahl1 + zahl2;
new Boxy.ask("Wie viel ist "+zahl1+" + "+zahl2+"? <input type='text' id='answ' />",
["Ok"],
function(val) {
if($("#answ").val() == (zahl1 + zahl2))
{
$("#form").submit();
}
else
{
ask();
return false;
}
},
{title: "Captcha"}
);
}
</script>
The code is a bit unclean... function call them selfts... i know... but how can i let call the "OK" event on Enter Press...
So you write the answer and press Enter... and it checks.
Have some an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过编程方式单击框上的“确定”按钮:
无论何时创建输入,都使用
live
监听事件。如果您有多个输入类型按钮(例如,如果添加“取消”按钮),则可能需要在检查回车键时修改选择器。在这里查看一个工作示例: http://jsfiddle.net/andrewwhitaker/Z2qeh/
注意:我尝试将您的匿名回调方法重构为自己的方法,该方法可以由 Boxy 对象和
keydown
侦听器调用,但我无法获得与单击“确定”按钮。You could programmatically click the 'Ok' button on the box:
Using
live
to listen to events no matter when the input is created. You may have to modify selector under the check for the enter key if you have more than one input of type button (if you add a "Cancel" button for example).Check out a working example here: http://jsfiddle.net/andrewwhitaker/Z2qeh/
Note: I tried refactoring your anonymous callback method into its own method that could be called by both the Boxy object and the
keydown
listener, but I couldn't get the interaction quite the same as clicking the "Ok" button.