判断文本框输入比例之和为100%

本文介绍了一段JavaScript代码,用于验证HTML表单中两个输入框的数值之和是否等于100。该功能常见于需要用户分配百分比的应用场景,确保用户输入的数据符合预期的比例要求。
if((document.myForm.blOne.value != "") || (document.myForm.blTwo.value != "")){
 var bl = parseFloat(document.myForm.blOne.value) + parseFloat(document.myForm.blTwo.value);
    if(bl != 100 ){
     alert("比例不对,请重新填写!");
     document.myForm.blOne.value = "";
     document.myForm.blTwo.value = "";
     ocument.myForm.blOne.focus();
     return false;
      }
 }
我想要输入90到100时在文本框中输出优秀,80到89时在文本框中输出良好,70到79时在文本框中输出中等,60到69时在文本框中输出及格,60以下的在文本框中输出不及格,那么我的代码应该怎么写,写在以下代码中的那个位置:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Score { class Program { static void Main(string[] args) { int nStudents; // 定义变量,用于统计学生人数 int temp_score; // 定义变量,接收每次输入的成绩 // 定义最大成绩与最小成绩 int max_score = 0, min_score = 0; // 统计成绩各区间内的成绩人数 int score_0_59 = 0, score_60_69 = 0, score_70_79 = 0, score_80_89 = 0, score_90_100 = 0; Console.WriteLine("--------- 学生成绩统计 ---------"); // 接收全班人数 Console.WriteLine("请输入班级人数: nStudents = "); string s = Console.ReadLine(); nStudents = Int32.Parse(s); // 接收并处理成绩 for (int i = 1; i <= nStudents; i++) { // 接收成绩 Console.WriteLine("请输入第{0:d}个学生的成绩", i); temp_score = Int32.Parse(Console.ReadLine()); // 修改最高与最低成绩 if (i == 1) { max_score = temp_score; min_score = temp_score; } else { if (max_score < temp_score) max_score = temp_score; if (min_score > temp_score) min_score = temp_score; } // 接收成绩所在区间的人数 int temp = temp_score / 10; switch (temp) { case 10: case 9: Console.WriteLine("优秀"); // 成绩优秀 score_90_100++; break; case 8: Console.WriteLine("良好"); // 成绩良好 score_80_89++; break; case 7: Console.WriteLine("中等"); // 成绩中等 score_70_79++; break; case 6: Console.WriteLine("及格"); // 成绩及格 score_60_69++; break; default: Console.WriteLine("不及格"); // 成绩不及格 score_0_59++; break; } } // 统计信息输出 Console.WriteLine("--------- 学生成绩统计信息输出 ---------"); Console.WriteLine("全班共{0:d}人,其中最高成绩{1:f2}," + "最低成绩{2:f2}", nStudents, max_score, min_score); Console.WriteLine("成绩区间90~100的人数有{0:d}人," + "所占比例为{1:f2}%", score_90_100, score_90_100 * 100 / nStudents); Console.WriteLine("成绩区间80~89的人数有{0:d}人," + "所占比例为{1:f2}%", score_80_89, score_80_89 * 100 / nStudents); Console.WriteLine("成绩区间70~79的人数有{0:d}人," + "所占比例为{1:f2}%", score_70_79, score_70_79 * 100 / nStudents); Console.WriteLine("成绩区间60~69的人数有{0:d}人," + "所占比例为{1:f2}%", score_60_69, score_60_69 * 100 / nStudents); Console.WriteLine("成绩区间0~59的人数有{0:d}人," + "所占比例为{1:f2}%", score_0_59, score_0_59 * 100 / nStudents); //Console.WriteLine($"全班共{nStudents}人,其中最高成绩{max_score},最低成绩{min_score}"); //Console.WriteLine($"成绩区间 90~100 分的人数:{score_90_100}"); //Console.WriteLine($"成绩区间 80~89 分的人数:{score_80_89}"); //Console.WriteLine($"成绩区间 70~79 分的人数:{score_70_79}"); //Console.WriteLine($"成绩区间 60~69 分的人数:{score_60_69}"); //Console.WriteLine($"成绩区间 0~59 分的人数:{score_0_59}"); } } }
10-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值