Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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 如何检查输入的值是否为10?_Javascript_Verify - Fatal编程技术网

Javascript 如何检查输入的值是否为10?

Javascript 如何检查输入的值是否为10?,javascript,verify,Javascript,Verify,我想检查输入的值是否为10(如果值为10,我想将结果发送到“send.php”)。我做错了什么 <?php $cod1=rand(0, 10); $cod2=10-$cod1; ?> <form action='send.php' method='post' onsubmit='f1(this)'> Please enter the value of <br> <?php echo $cod1 ?> + <

我想检查输入的值是否为10(如果值为10,我想将结果发送到“send.php”)。我做错了什么

<?php  $cod1=rand(0, 10); 
    $cod2=10-$cod1; ?>   
    <form action='send.php'  method='post' onsubmit='f1(this)'>
    Please enter the value of <br> <?php echo $cod1 ?> + <?php echo $cod2 ?> in the following box
    <input type="text" name="xrezultat" id="xrezultat" class="box" size="32"/>

    <input name="Submit1" type="submit" class="butt" value="Trimiteti">      
    <input name="Submit2" type="reset" class="butt" value="Stergeti ">

    </form>


    <Script> 
    function f1(input) 
    {    
    if(document.getElementById("xrezultat").value!=10)   
    aux==false;

     if (aux == true)
    {
       return true;
    }

       else
    {
        alert ( "Please enter the correct value" );
        return false;
                 }


    }
    </script>

请在下面的框中输入
+的值 功能f1(输入) { if(document.getElementById(“xrezultat”).value!=10) aux==假; 如果(aux==true) { 返回true; } 其他的 { 警报(“请输入正确的值”); 返回false; } }
尝试使用
parseInt

var numberValue = parseInt(document.getElementById("xrezultat").value, 10);

aux==false检查
aux
是否等于false,它不会分配给它


应读取
aux=false

onsubmit='returnf1(this)'
//返回值丢失,这是否重要?字符串
“10”
=
到int
10
。(与
==
不同)@Dev问题是我有2个x“=”而不是我应该有的唯一一个。不管我是否返回……为什么你的函数有一个从未使用过的
输入
参数?@Snuffleupageus非常感谢!我是否可以检查输入的值是否是数字,而不是字符串或字符?@euloli check out answer验证数字。