将两个javascript代码合并为一个代码分隔符
我需要创建一个可重用的函数。以下脚本应阻止表单提交并显示div警报。此版本不阻止表单提交 函数hideobj{ var el=document.getElementByIdobj; el.style.display='none'; } $function{ $'formvendiendo'。提交函数{ 如果编号为$venta.val< 编号$costo.val{ $warnings.show; //这里开始我添加的新代码 如果编号$cantidad.val> 编号$stock.val{ $warnings2.show; //我添加的新代码到此结束 返回false; } }; };将两个javascript代码合并为一个代码分隔符,javascript,jquery,Javascript,Jquery,我需要创建一个可重用的函数。以下脚本应阻止表单提交并显示div警报。此版本不阻止表单提交 函数hideobj{ var el=document.getElementByIdobj; el.style.display='none'; } $function{ $'formvendiendo'。提交函数{ 如果编号为$venta.val< 编号$costo.val{ $warnings.show; //这里开始我添加的新代码 如果编号$cantidad.val> 编号$stock.val{ $war
如果希望在出现错误时停止表单提交,则应该这样做
<script type="text/javascript">
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
$(function() {
$('form#vendiendo').submit(function(e) {
if(Number($("#venta").val()) < Number($("#costo").val())) {
$("#warnings").show();
// You're still in the first if() statement. Is that what you want?
if (Number($("#cantidad").val()) > Number($("#stock").val())) {
// At this point, both checks have failed. We want to stop the
// default behavior.
e.preventDefault();
e.stopPropagation();
// And tell the user why we failed.
$("#warnings2").show();
return false;
}
});
});
</script>
我认为2如果是错误的…:你的大括号不平衡。为什么php被标记?使用一个缩进代码的编辑器,这样你就可以看到结构,它将帮助你正确编程。我怎么做酒吧男?我是javascriptthe表单提交的新手。无论如何,你有在服务器上的某个地方,我们可以看到HTML与此一起吗?还有,这可能是他lp:看一看