اليوم شعرت بالملل وأردت كتابة شيء ما ، لكنني فكرت فجأة في كتابة حاسبة في جافا سكريبت. لا يزال هناك العديد من الأخطاء في البرنامج. سأقوم بتسجيله هنا أولاً ثم تصحيحه ببطء لاحقًا.
الرمز كما يلي:
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3 xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8"/> type = "text/css"> input {width: 30px ؛ height: 20px ؛ text-align: center ؛}#tbcalculator td {text-align: center ؛ allign align: middle ؛} </style> <script type = "text/javaScript"> var stree ؛ // احفظ القيمة الرقمية في مربع الإدخال قبل مشغل النقر ؛ // حفظ المشغل var ispressequalskey = false ؛ // سجل ما إذا كنت تريد الضغط أو لا "=" KEY // مفتاح الحدث ، connectionDigital (control) {var txt = document.getElementById ('txtscream') ؛ if (ispressequalekey) {txt.value = "" ؛ // تم إجراء الحساب ، ثم قم بمسح مربع الإدخال العددي وابدأ مرة أخرى في ISpressequalskey = false ؛} // النقطة العشرية موجودة بالفعل في المدخلات العددية ، ثم لا يُسمح بالنقطة العشرية إلى إدخالها (txt.value.indexof ('.')> -1 && control.value == '. // قم بتعيين قيمة التحكم إلى مربع الإدخال العددي} // packspace function packspace () {var txt = document.getElementById ('txtscream') ؛ txt.value = txt.value.substring (0 ، txt.value.length - 1) ؛} ClearAll () {document.getElementById ('txtscream'). value = "" ؛ result = "" ؛ operator = "؛} // +، -، *،//event function calculation (control) {// save the corpator in the global variable complator = control.value ؛ var txt = document.getElementById ('txtscream') ؛ if (txt.value == "") return false ؛ // لا يوجد رقم في مربع الإدخال العددي ، ثم لا يمكن إدخال المشغل // حفظ القيمة في مربع الإدخال العددي في نتيجة تعبير الحساب = txt.value ؛ // قم بمسح مربع الإدخال المراد إدخاله إلى قيمة التشغيل txt.value = "" ؛ } // دالة نتائج الحساب getResult () {var opvalue ؛ // المشغل var sourceValue = parsefloat (result) ؛ var txt = document.getElementById ('txtscream') ؛ if (downporator == ' *') opvalue = soursevalue * parsefloat (txt.val) ؛ soursevalue / parsefloat (txt.value) ؛ else إذا (المشغل == ' +') opvalue = soursevalue + parsefloat (txt.value) ؛ else elf (dorpator == ' -') opvalue = soursevalue - parsefloat (txt.value) ؛ "" ؛ opvalue = "" ؛} </script> </head> <body> <body> <table id = "tbcalculator" align = "center" cellpadding = "0" cellpacing = "0 readonly = "readonly"/> </td> </tr> <tr> <td colspan = "2"> <input type = "button" name = "btnce" id = "btnce value =" ce "align =" right "؛ onClick = "clearall () ؛" /> </td> <td colspan = "2"> <input type = "button" name = "btn10" id = "btn10" value = "backspace" align = "right" ؛ onClick = "Backspace () ؛" /> </td> </tr> <tt> <td> <type type = "button" name = "btn7" id = "btn7" value = "7" onClick = "connectionDigital (this) ؛" /> </td> <td> <type type = "button" name = "btn8" id = "btn8" value = "8" onClick = "connectionDigital (this) ؛"/> </td> <td> <tded type = "button" name = "btn9" id = "btn9" value = "9" /> </td> <td> <input type = "button" name = "btn6" id = "btn6" value = "/" onClick = "calculation (this) ؛" /> </td> </tr> <tt> <td> <type type = "button" name = "btn4" id = "btn4" value = "4" onClick = "connectionDigital (this) ؛"/> </td> <td> <input type = "button" name = "btn5" id = "btn5" onClick = "connectionDigital (this) ؛"/> </td> <td> <td input type = "button" name = "btn6" id = "btn6" value = "6" onClick = "connectionDigital (this) ؛"/> </td> <td> <td type type = "button" = btn13 "id =" btn1 "* onClick = "الحساب (هذا) ؛" /> </td> </td> <td> <td> <type type = "button" name = "btn1" id = "btn1" value = "1" onClick = "connectionDigital (this) ؛"/> </td> <td> <input type = "button" name = "btn2" id = "btn2" id = "btn2" onClick = "connectionDigital (this) ؛"/> </td> <td> <tde type = "button" name = "btn3" id = "btn3" value = "3" onClick = "connectionDigital (this) ؛"/> </td> <td> <two type type = "button" = "btn18" onClick = "الحساب (هذا) ؛" /> </td> </tr> <tr> <td> <input type = "button" name = "btn0" id = "btn0" value = "0" onClick = "connectionDigital (this) ؛" /> </td> <td> <input type = "button" name = "btndot" id = "btndot" value = "." onClick = "ConnectionDigital (هذا) ؛" /> </td> <td> <input name = "btn22" type = "button" id = "btn22" value = "=" onClick = "getResult () ؛" /> </td> <td> <input type = "button" name = "btn23" id = "btn23" value = "+" onClick = "COLACULITY (this) ؛" /> </td> </tr> </table> </body> </html>الكود أعلاه لتنفيذ حاسبة بسيطة في JavaScript هو كل المحتوى الذي شاركته معك. آمل أن تتمكن من إعطائك مرجعًا وآمل أن تتمكن من دعم wulin.com أكثر.