التأثير النهائي كما هو موضح في الشكل 2. إذا تم النقر على ٪ بعد عشري ، ستكون النتيجة خاطئة! الباقي طبيعي ، من فضلك أعطني بعض النصائح: قيمة الإدخال من نوع السلسلة. كيفية التعامل بشكل صحيح مع الجزء IF في الشكل 1 أدناه في JS؟ ؟
الشكل 1
الشكل 2
رمز HTML كما يلي
<Body> <div id = "calculator"> <viv> <span> حاسبة بسيطة </span> <span> walker </span> </viv> <div id = "shuru"> <!-شريط إدخال الشاشة-> <div> <input type = "text" id = "screenname" name = "screenname"> type = "button" id = "7" onClick = "jsq (this.id)" value = "7"> <input type = "button" id = "8" onClick = "JSQ (this.id)" value = "8" value = "back"> <input type = "button" id = "c" onClick = "clearnum ()" value = "c" style = "margin-right: 0px"> <! <type type = "button" id = "6" onClick = "jsq (this.id)" value = "6"> <input type = "button" id = "*" onClick = "jsq (this.id) type = "button" id = "1" onClick = "jsq (this.id)" value = "1"> <input type = "button" id = "2" onClick = "jsq (this.id) onClick = "jsq (this.id)" value = "+"> <input type = "button" id = "-" onClick = "jsq (this.id)" value = "-" style = "margin-right: 0px"> <! OnClick = "JSQ (this.id)" value = "00"> <input type = "button" id = "." onClick = "jsq (this.id)" value = ". <a href = "#" target = "_ blank"> التغذية المرتدة </a> </span> </viv> </viv> </body>
رمز CSS كما يلي:
<Style> /*basic reset* /*{margin: 0 ؛ الحشو: 0 ؛ حجم الصناديق: صندوق الحدود ؛ الخط: 14px arial ، sans-serif ؛} html {الارتفاع: 100 ٪ ؛ خلفية اللون: lightslategrey ؛}#الآلة الحاسبة {margin: 15px Auto ؛ العرض: 330 بكسل ؛ الارتفاع: 400 بكسل ؛ الحدود: 1 بكسل ضوئي الصلب. خلفية اللون: Darkgrey ؛ padding: 15px ؛}/*logo*/. logo {height: 20px ؛}. logo .Name {float: left ؛ Line-Height: 30px ؛}. Logo .verson {float: right ؛ Line-Height: 30px ؛}/*screen*/#Shuru {margin-top: 15px ؛}. الشاشة {margin-top: 5px ؛ العرض: 300 بكسل ؛ الارتفاع: 40 بكسل ؛ محاذاة النص: صحيح ؛ حشو اليمين: 10 بكسل ؛ حجم الخط: 20px ؛}#مفاتيح {الحدود: 1px lightgray الصلبة ؛ الارتفاع: 223 بكسل ؛ الهامش: 25 بكسل ؛ Padding: 8px ؛}#Keys .last {Margin-Right: 0px ؛}. الارتفاع: 20px ؛}. العرض: 42 بكسل ؛ الارتفاع: 36 بكسل ؛ محاذاة النص: المركز ؛ خلفية اللون: Lightgray. الهامش: 0 17px 20px 0 ؛} </style>رمز JavaScript كما يلي:
<script> var num = 0 ؛ // تحديد بيانات وظيفة الإدخال الأولى jsq (num) {// الحصول على الإدخال الحالي if (num == "٪") {document.getElementById ('screenname'). value = math.Round (document.getElementById ('screenname'). value)/100 ؛ } آخر {document.getElementById ('screenname'). value += document.getElementById (num) .value ؛ }} function eva () {// حساب مستند نتائج الإدخال. } الدالة clearNnum () {// clear 0 document.getElementById ("screenname"). value = null ؛ document.getElementById ("screenname"). Focus () ؛ } function tuige () {// backspace var arr = document.getElementById ("screenname") ؛ arr.value = arr.value.substring (0 ، arr.value.length - 1) ؛ } </script>المقالة أعلاه JavaScript تنفذ تأثير حاسبة بسيط [الموصى بها] هو كل المحتوى الذي أشاركه معك. آمل أن تتمكن من إعطائك مرجعًا وآمل أن تتمكن من دعم wulin.com أكثر.