我试图在网络表单中禁用回车键。 Web表单由Javascript函数设置"初始化"。在该函数中,我添加了以下代码:
$('html').bind('keypress', function(e)
{
if(e.keyCode == 13)
{
return false;
}
});
这适用于除一个按钮之外的每个按钮。在我的大部分屏幕上,我都有一个"继续"按钮,设置如下(来自开源第三方库):
that.continueButton = function (obj) {
var str = ""
if (typeof obj==="string") {
obj = {label: obj}
}
if (!obj) {
obj = {};
}
if (!obj.label) {
obj.label = Experigen.settings.strings.continueButton;
}
str += '<input type="button" value="' + obj.label + '" ';
var spec = [];
if (obj.hide===true) {
spec.push("hide:true");
}
if (obj.disable===true) {
spec.push("disable:true");
}
spec = spec.length ? ",{" + spec.join(",") + "}" : "";
//add answer before advancing
str += 'onClick="Experigen.screen().continueButtonClick(this' + spec + ');">'
return str
}
/**
* Forwards the experiment: calls {@link Experigen.trial.advance} or {@link Experigen.advance} as needed
* @method
* @memberof Experigen.trial
*/
that.continueButtonClick = function (caller, spec) {
//Add training block information and user responses
if (Experigen.screen().soundbuttons[0] != undefined)
{
Experigen._screens[Experigen.position].Listens = Experigen.screen().soundbuttons[0].presses;
}
Experigen._screens[Experigen.position].Answer = $("input[name=answergiven]").val();
Experigen._screens[Experigen.position].TrainingBlock = Experigen.settings.training_block;
var comingFrom = Experigen.screen().findCaller(caller);
if (comingFrom && comingFrom.attr("class")==="trialpartWrapper") {
Experigen.screen().advance(spec);
} else {
Experigen.advance(caller);
}
}
正如您可能已经猜到的那样,输入键&#34;点击&#34;此按钮将用户移动到下一个屏幕。这是唯一未禁用回车键的按钮。有没有人对这可能是什么有任何想法?
答案 0 :(得分:1)
正如@epascarello在上述评论中指出的那样,将“按键”更改为“keydown”就可以了。