Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交can';不要看到返回错误;_Javascript_Jquery_Forms_Submit - Fatal编程技术网

Javascript 提交can';不要看到返回错误;

Javascript 提交can';不要看到返回错误;,javascript,jquery,forms,submit,Javascript,Jquery,Forms,Submit,我知道我必须加上返回错误;在onsubmit中调用to函数(我在HTML中将其添加到function和onsubmit=“”)。但它不起作用。。。按Enter键或单击submit按钮后刷新页面 JavaScript生成的表单: AnswersHTML += "<div><form onsubmit='cheking(this," + a + "," + b + ", this); return false;'><input class='put' type='tex

我知道我必须加上返回错误;在onsubmit中调用to函数(我在HTML中将其添加到function和onsubmit=“”)。但它不起作用。。。按Enter键或单击submit按钮后刷新页面

JavaScript生成的表单:

AnswersHTML += "<div><form onsubmit='cheking(this," + a + "," + b + ", this); return false;'><input class='put' type='text' size='40'><input type='submit' value='Проверить'></form>
AnswersHTML+=”
和功能

function checking(answer, nums, numq, what) {
var usr = answer;
if (isNaN(answer)) {
    usr = answer.value;
    if (answer.value.length == "") {
        usr = "Вы ничего не ввели!"
    }
    else {
        answer = answer.value.toLowerCase();
    }
}
if (answer == correct[nums][numq]) {
    $(what).parent().parent().append("<br><span class='right'>Ответ: " + usr + "<br>Правильно!</span>").slideDown();
    $(what).parent().parent().find(".put").remove();
    $("#board").animate({ backgroundColor: '#2ecc71'});
    $("#board").animate({ backgroundColor: '#f1c40f'}, 1000);
    if (isPhysics[nums][numq]) {
        physics++;
        $("#presult").text(physics);
    }
    else {
        life++;
        $("#lresult").text(life);
    }
}
else {
    $("#board").animate({ backgroundColor: '#e74c3c'});
    $("#board").animate({ backgroundColor: '#f1c40f'}, 1000);
    var desciptionToWrong = "<br>" + description[nums][numq];
    if (description[nums][numq] == false) {
        desciptionToWrong = ""
    }
    $(what).parent().parent().append("<br><span class='wrong'>Ответ: " + usr + "<br>Неправильно!" + desciptionToWrong + "</span>")
    $(what).parent().parent().find(".put").remove();
    $(what).remove(".pressenter");
}
return false;
函数检查(应答、nums、numq、什么){
var usr=答案;
如果(isNaN(回答)){
usr=答案值;
if(answer.value.length==“”){
usr=“ччччччччч!”
}
否则{
answer=answer.value.toLowerCase();
}
}
如果(答案==正确[nums][nummq]){
$(what).parent().parent().append(
Саааааааааааааааа; $(what).parent().parent().find(“.put”).remove(); $(“#board”).animate({backgroundColor:'#2ecc71'}); $(“#board”).animate({backgroundColor:'#f1c40f'},1000); 如果(iPhysics[nums][nummq]){ 物理++; $(“假定”)。文本(物理); } 否则{ 生活++; $(“#lresult”)。文本(生活); } } 否则{ $(“#board”).animate({backgroundColor:'#e74c3c'}); $(“#board”).animate({backgroundColor:'#f1c40f'},1000); var descriptiontowrong=“
”+说明[nums][nummq]; if(说明[nums][nummq]==false){ descriptionTowRong=“” } $(what).parent().parent().append(“
Саааааааааааааааа107 $(what).parent().parent().find(“.put”).remove(); $(什么)。删除(“.按Enter”); } 返回false;
}

对不起,我的代码可能很恶心

这是全文


函数中出现问题,因为当我将函数替换为“仅警报”时,一切正常

这可能是由于类型。函数调用中存在拼写错误,这将导致错误,调用将转到服务器

改变


您的内联onclick有一个输入错误,您在函数名中留下了一个c。此错误可能会在click处理程序到达return语句之前终止它。

试试这个

 AnswersHTML += "<div><form data-a='"+a+"' data-b='"+b+"' class='myform'><input class='put... "

尝试
返回检查(…);
而不仅仅是
检查(…)
检查
方法中几乎没有脚本错误。
参数
应答
指的是
表单
元素,而不是
输入
元素…因此
应答.值
将未定义,
应答.值.长度
抛出错误如果函数设置为onload,则无法工作。请尝试将其放入内容的开头或结尾body@ArunP Johny但是chrome控制台会像其他人建议的那样检查拼写错误,
这个
的意思是“形式”而不是像Arun说的“输入”。
 'checking(this," + a + "," + b + ", this);  
 AnswersHTML += "<div><form data-a='"+a+"' data-b='"+b+"' class='myform'><input class='put... "
$(function(){
    $(document).on('submit','form.myform',function(){
        checking(this, $(this).data('a'),  $(this).data('b'), this);
        return false;
    });
});