gpt4 book ai didi

javascript - 为什么验证函数不执行

转载 作者:行者123 更新时间:2023-12-02 16:04:34 25 4
gpt4 key购买 nike

我尝试使用 jquery 验证表单,但函数“validacion()”不起作用。

我正在 apache 和 eclipse 上进行。

表格

<form action="destino.html" method="post" id="formularioDarAlta" onsubmit="return validacion();">
<fieldset>
<legend>Formulario alta libro</legend>
...
<p>
<input type="submit" value="Insertar"/>
</p>
</fieldset>
</form>

脚本

<script>
function validacion()
{
var isbn = $('#isbn').val();
var titulo = $('#titulo').val();
var categoria = $('#categoria').val();
var respuesta = true;

if(isbn.value == "")
{
alert("Debe ingresar ISBN");
respuesta = false;
}
if(titulo.value == "")
{
alert("Debe ingresar título");
respuesta = false;
}
if(categoria.value == "")
{
alert("Debe ingresar categoría");
respuesta = false;
}
return respuesta;
}
</script>

最佳答案

您不需要使用 isbn.value 因为您已经使用了 $('#isbn').val()这是一个带有更新代码的 fiddle http://jsfiddle.net/674hv53e/1/

 if(isbn == "")
{
alert("Debe ingresar ISBN");
respuesta = false;
}

关于javascript - 为什么验证函数不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30895017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com