本文介绍了简单的区域和周边计算器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿所有。 只是想知道是否有人可以告诉我我做错了什么。 新编码已经完成了一些这样的事情但似乎没有上班时间:/ 以下是代码 我尝试过: < !DOCTYPE html > < html > < head > < script > var $ = function (id){ // 从文本框中获取信息到脚本的其余部分 return document .getElementById(id); } // 美元函数结束 function calculateArea(){ // 使用用户输入计算区域 var width = document .getElementById( width) .value; var length = document.getElementByID( length )。值; var area = length.value * width.value; //计算面积 area = area.toFixed(2); var perimeter = width * 2 + length * 2; document.getElementById('area')。value = area; document.getElementByID('perimeter')。value = perimeter; } //结束计算区域函数 函数calculatePerimeter(长度,宽度){//使用用户输入计算周长 var perimeter = width.value * 2 + length.value * 2; //周长计算周长= perimeter.toFixed(2); 返回周长; //输出计算} //计算完成度函数结束 函数processEntries(){ var length = parseFloat($( length )。value); var width = parseFloat($( width )。value); $( area )。value = calculateArea(); $( perimeter )。value = calculatePerimeter(); alert( test ); } } //结束进程电子 window.onload = function(){//等待用户点击按钮然后处理 alert( test1 ); $(计算 )。onclick = processEntries; //进程输入 $( length )。focus(); //使其闪烁等待用户输入 } //点击命令上的按钮结束 < / script> < / head> < body> < main> < h1>面积和面积周长计算器< / h1>< br> < label for = intructions >在下面输入数值,然后点击计算 。< / label>< br> < p>< label for = length >长度:< /标签> < input type = text id = length >< br> < label for = width >宽度:< / label> < input type = text id = width >< br> < label for = area > Area:< / label> < input type = text id = area >< br> < label for = perimeter >周长:< / label> < input type = text id = perimeter >< br> < label> < /标签> < input type =按钮 id =计算 value =计算面积和周长 > < / br>< / br>< / br>< / br>< / p>< / br>< / br>< / main> < / body> < / html> 解决方案 = function (id){ // 从文本框获取信息到脚本的其余部分 return document .getElementById(id); } // 美元函数结束 function calculateArea(){ // 使用用户输入计算区域 var width = document .getElementById( width) .value; var length = document.getElementByID( length )。值; var area = length.value * width.value; //计算面积 area = area.toFixed(2); var perimeter = width * 2 + length * 2; document.getElementById('area')。value = area; document.getElementByID('perimeter')。value = perimeter; } //结束计算区域函数 函数calculatePerimeter(长度,宽度){//使用用户输入计算周长 var perimeter = width.value * 2 + length.value * 2; //周长计算周长= perimeter.toFixed(2); 返回周长; //输出计算} //计算完成度函数结束 函数processEntries(){ var length = parseFloat( ( length )。value); var width = parseFloat( ( width )值); Hey all.Just wondering if someone could tell me what im doing wrong.New to coding have done a few things like this but it doesn't seem to work :/Below is the codeWhat I have tried:<!DOCTYPE html><html><head><script>var $ = function(id){ //gets information from the text box to rest of scriptreturn document.getElementById(id);} //end of dollar function function calculateArea(){ //calculates the area using the users inputvar width = document.getElementById("width")".value;var length = document.getElementByID("length").value;var area = length.value * width.value; //calculation for areaarea = area.toFixed(2); var perimeter = width * 2 + length * 2;document.getElementById('area').value = area;document.getElementByID('perimeter').value = perimeter;} //end of calculateArea functionfunction calculatePerimeter (length,width){ //calculates the perimeter using the users inputsvar perimeter = width.value*2 + length.value*2; //calculation for perimeter perimeter = perimeter.toFixed(2);return perimeter; //outputs the calcultion} //end of calculatePerimeter functionfunction processEntries(){ var length = parseFloat($("length").value);var width = parseFloat($("width").value);$("area").value = calculateArea();$("perimeter").value = calculatePerimeter();alert("test"); }} //end of processEnterieswindow.onload = function(){ //waits for the user to click the button then processesalert("test1");$("calculate").onclick = processEntries; //processes input$("length").focus();//makes it flash waiting for users input}// end of button on click command</script></head><body><main> <h1> Area & Perimeter Calculator </h1><br> <label for="intructions">Enter numerical values below and click "Calculate".</label><br><p><label for="length">Length: </label><input type="text" id="length"><br><label for="width">Width: </label><input type="text" id="width"><br><label for="area">Area: </label><input type="text" id="area"><br><label for="perimeter">Perimeter: </label><input type="text" id="perimeter"><br><label> </label> <input type="button" id="calculate" value="Calculate Area and Perimeter"></br></br></br></br></p></br></br></main></body></html> 解决方案 = function(id){ //gets information from the text box to rest of scriptreturn document.getElementById(id);} //end of dollar function function calculateArea(){ //calculates the area using the users inputvar width = document.getElementById("width")".value;var length = document.getElementByID("length").value;var area = length.value * width.value; //calculation for areaarea = area.toFixed(2); var perimeter = width * 2 + length * 2;document.getElementById('area').value = area;document.getElementByID('perimeter').value = perimeter;} //end of calculateArea functionfunction calculatePerimeter (length,width){ //calculates the perimeter using the users inputsvar perimeter = width.value*2 + length.value*2; //calculation for perimeter perimeter = perimeter.toFixed(2);return perimeter; //outputs the calcultion} //end of calculatePerimeter functionfunction processEntries(){ var length = parseFloat(("length").value);var width = parseFloat(("width").value); 这篇关于简单的区域和周边计算器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-21 00:51