【发布时间】:2020-09-22 11:42:06
【问题描述】:
对不起,我的愚蠢问题,但我不熟悉 JQuery。我想仅在用户单击特定按钮时检查字段值是否大于其他字段值。我的表单上有两个按钮,用于提交具有不同按钮值的值。 这是我不知道怎么写的JavaScript代码:
$(document).ready(function(){
// If click on DKV button, check thaht field prix_total > litrage
// else if click on GR, do not check that prix_total > litrage
$("#creer_carburant_DKV").click(function(){
var price = $("#prix_total").val();
var liter = $("#litrage").val();
if (price > liter){
// send the form
}else{
alert("The price must be greater than liter");
}
$("#creer_carburant_GR").click(function(){
// If prix_total is not set, define to 0
});
这是 JSFiddle 上的一个工作示例:https://jsfiddle.net/04mpbfcx/
【问题讨论】:
标签: javascript jquery forms validation button