Jquery 提交运行,即使停止传播
我想滑动切换表单,使其仅在有人想使用表单时显示。尝试切换表单时正在运行提交代码。我使用了停止传播,但它不起作用Jquery 提交运行,即使停止传播,jquery,Jquery,我想滑动切换表单,使其仅在有人想使用表单时显示。尝试切换表单时正在运行提交代码。我使用了停止传播,但它不起作用 $(document).ready(function() {//ready function if($('#calculator')) {//if this id exists on the page $('#calculatorInputs').css('display','none');
$(document).ready(function() {//ready function
if($('#calculator')) {//if this id exists on the page
$('#calculatorInputs').css('display','none');
$('#calculator h3').click(function() {
$('#calculatorInputs').slideToggle('slow', function() {
// Animation complete.
});
});
$('#Original_Wattage').addClass('focusOn');
$("input").focus(function(){//applies a background color to current input
$(this).addClass('focusOn');
});
$("input").focusout(function(){//removes background color from current input
$(this).removeClass('focusOn');
});
$('input').focusout(function() {//start of focusout
$validateThis = $(this).attr("id");
$currentValue = $(this).val();
switch ($validateThis) {//validates the entries in the various form fields
case 'Replacement_Wattage':
if($currentValue < 1 || $currentValue > 2000 || $currentValue == "" || isNaN($currentValue) ) {
alert('Please enter a Replacement Fixture Wattage between 1 and 2000');
setTimeout(function() { $('#Replacement_Wattage').focus(); },50);//setTimeOut
}
break;
case 'Original_Wattage':
if($currentValue < 1 || $currentValue > 2000 || isNaN($currentValue) ) {
setTimeout(function() { $('#Original_Wattage').focus(); },50);//setTimeOut
alert('Please Replace the Original Lamp Wattage between 1 and 2000');
}
break;
case 'Number_of_Lamps':
if($currentValue < 1 || isNaN($currentValue) ) {
setTimeout(function() { $('#Number_of_Lamps').focus(); },5);//setTimeOut
alert('Please input the number of lamps.');
}
break;
case 'Hours':
if($currentValue < 1 || $currentValue >24 || isNaN($currentValue) ) {
setTimeout(function() { $('#Hours').focus(); },5);//setTimeOut
alert('Please input number of hours not exceeding 24.');
}
break;
case 'Days':
if($currentValue < 1 || $currentValue > 7 || isNaN($currentValue) ) {
setTimeout(function() { $('#Days').focus(); },5);//setTimeOut
alert('Please input number of days not exceeding 7.');
}
break;
case 'Weeks':
if($currentValue < 1 || $currentValue > 52 || isNaN($currentValue) ) {
setTimeout(function() { $('#Weeks').focus(); },5);//setTimeOut
alert('Please input number of weeks not exceeding 52.');
}
break;
case 'Energy_Cost':
if($currentValue < 0 || $currentValue > .99999 || isNaN($currentValue) ) {
setTimeout(function() { $('#Energy_Cost').focus(); },5);//setTimeOut
alert('Please input a number between 0 and 1 in decimal form.');
}
break;
}// end of switch statement
});//end of input focusout code
$("#submit").click(function(e) {//submits to update the savings
e.preventDefault();
if($OriginalFixtureType = $('input:radio[name="Original_Fixture_Type"]:checked').val()) {//if lamp type is checked, then wt
$OriginalFixtureType = $('input:radio[name="Original_Fixture_Type"]:checked').val();
$currentOriginal_Wattage = parseInt($('#Original_Wattage').val()) * 1.05;
} else {
$currentOriginal_Wattage = parseInt($('#Original_Wattage').val());
}
$currentLampType = $('#Lamp_Type').val();//finds lamp type in hidden field - adjusts wattage based upon lamp type
if($currentLampType == "High Pressure Sodium (HPS)" || $currentLampType =="Pulse Start - Metal Halide (PS-MH)" || $currentLampType == "Metal Halide (PS-MH)") {
$currentReplacement_Wattage = parseInt($('#Replacement_Wattage').val() * 1.05);
} else {
$currentReplacement_Wattage = parseInt($('#Replacement_Wattage').val());
}
if(isNaN($currentOriginal_Wattage) || $currentOriginal_Wattage < 1 ) {
alert('Sorry you have either not entered a value for your Original Wattage OR the wattage is not between 1 and 2000 OR it is lower than Replacement Wattage.');
} else {
$kilowattsSaved = (($currentOriginal_Wattage - $currentReplacement_Wattage ) * $('#Number_of_Lamps').val() ) / 1000;
$kilowattsSavedPerYear = ( $('#Hours').val() * $('#Days').val() * $('#Weeks').val() ) * $kilowattsSaved;
$dollarSavings = parseFloat($('#Energy_Cost').val() * $kilowattsSavedPerYear).toFixed(2);
$validateThis = $('#Replacement_Wattage').val();
$('p.kilowattsSaved').text('Total Kilowatts saved are: ' + $kilowattsSaved + 'kw');
$('p.kilowattsSavedPerYear').text('Total Kilowatts saved Per Year are: ' + $kilowattsSavedPerYear) + 'kw per year';
$('p.annualDollarSavings').html('Annual Dollar Savings: <span class="dollars">$' + $dollarSavings) + "</span>";
}
});//end of submit
}//end of if find calculator id on the page
});//end ready function
$(文档).ready(函数(){//ready函数
if($('#calculator')){//如果此id在页面上存在
$('#calculatorInputs').css('display','none');
$(“#计算器h3”)。单击(函数(){
$(“#计算器输入”).slideToggle('slow',function(){
//动画完成。
});
});
$('Original#u Wattage')。addClass('focusOn');
$(“输入”).focus(函数(){//将背景色应用于当前输入
$(this.addClass('focusOn');
});
$(“输入”).focusout(函数(){//从当前输入中删除背景色
$(this.removeClass('focusOn');
});
$('input').focusout(函数(){//focusout的开始
$validateThis=$(this.attr(“id”);
$currentValue=$(this.val();
switch($validateThis){//验证各种表单字段中的条目
“更换瓦数”情况:
如果($currentValue<1 | |$currentValue>2000 | |$currentValue==“”| | isNaN($currentValue)){
警报('请输入介于1和2000之间的更换夹具瓦数');
setTimeout(function(){$('#Replacement_Wattage').focus();},50);//setTimeout
}
打破
“原始瓦数”情况:
如果($currentValue<1 | |$currentValue>2000 | | isNaN($currentValue)){
setTimeout(function(){$('#Original_Wattage').focus();},50);//setTimeout
警报('请更换1到2000之间的原灯瓦数');
}
打破
案例“灯的数量”:
如果($currentValue<1 | | isNaN($currentValue)){
setTimeout(函数(){$('#灯的数量')。焦点();},5);//setTimeout
警报('请输入灯的数量');
}
打破
案件"时间":
如果($currentValue<1 | |$currentValue>24 | | isNaN($currentValue)){
setTimeout(function(){$('#Hours').focus();},5);//setTimeout
警报('请输入不超过24小时的小时数');
}
打破
案件‘天’:
如果($currentValue<1 | |$currentValue>7 | | isNaN($currentValue)){
setTimeout(function(){$('#Days').focus();},5);//setTimeout
警报('请输入不超过7天的天数');
}
打破
案件‘星期’:
如果($currentValue<1 | |$currentValue>52 | | isNaN($currentValue)){
setTimeout(function(){$('#Weeks').focus();},5);//setTimeout
警报('请输入不超过52周的周数');
}
打破
“能源成本”案例:
如果($currentValue<0 | |$currentValue>0.9999 | | isNaN($currentValue)){
setTimeout(function(){$('#Energy_Cost').focus();},5);//setTimeout
警报('请以十进制形式输入一个介于0和1之间的数字');
}
打破
}//开关结束语句
});//输入焦点输出代码的结尾
$(“#提交”)。单击(函数(e){//submits以更新节省的资源
e、 预防默认值();
如果($OriginalFixtureType=$('input:radio[name=“Original_Fixture_Type”]:checked').val(){//如果选中了灯类型,则wt
$OriginalFixtureType=$('input:radio[name=“Original_Fixture_Type”]:checked').val();
$currentOriginal_Wattage=parseInt($('Original_Wattage').val())*1.05;
}否则{
$currentOriginal_Wattage=parseInt($(“#Original_Wattage”).val();
}
$currentLampType=$(“#Lamp_Type”).val();//在隐藏字段中查找灯类型-根据灯类型调整瓦数
if($currentLampType==“高压钠(HPS)”| |$currentLampType==“脉冲启动-金属卤化物(PS-MH)”| |$currentLampType==“金属卤化物(PS-MH)”){
$currentReplacement_Wattage=parseInt($('Replacement_Wattage').val()*1.05);
}否则{
$currentReplacement_Wattage=parseInt($(“#Replacement_Wattage”).val();
}
if(isNaN($currentOriginal_瓦数)| |$currentOriginal_瓦数<1){
警报('很抱歉,您没有输入原始瓦数的值,或者瓦数不在1和2000之间,或者低于替换瓦数');
}否则{
$kwowssaved=($currentOriginal_Wattage-$currentReplacement_Wattage)*$(“#灯的数量”).val())/1000;
$kwowssavedperyear=($('小时').val()*$('天').val()*$('周').val())*$kwowssaved;
$dollarSavings=parseFloat($(“#能源成本”).val()*$kwowssavedperyear.toFixed(2);
$validateThis=$('#替换