Показать сообщение отдельно
  #12 (permalink)  
Старый 14.10.2016, 21:41
Профессор
Отправить личное сообщение для warren buffet Посмотреть профиль Найти все сообщения от warren buffet
 
Регистрация: 08.07.2016
Сообщений: 1,332

<!DOCTYPE html>
<html lang="ru" dir="ltr">
<head>
<meta charset="utf-8">
<style>

.mega-calc{
	border-collapse:collapse;
}

.mega-calc tr {
	border:1px solid #eee;
}

.mega-calc td {
	text-align:center;
	padding:3px;
}

</style>
</head>
<body>
<font color="RED" size="18"><B>CALC</B></font> <br/>

<form name="sci-calc" id="form-mega-calc">

<table class="mega-calc"><tbody> 

<tr>

	<td><input type="button" value="1"></td>
	<td><input type="button" value="2"></td>
	<td><input type="button" value="3"></td>
	<td><input type="button" value="4"></td>
	<td><input type="button" value="5"></td>
	<td><input type="button" value="6"></td>
	<td><input type="button" value="7"></td>
	<td><input type="button" value="8"></td>
	<td><input type="button" value="9"></td>
	<td><input type="button" value="0"></td>
	<td><input type="button" value="."></td>

</tr>


<tr>

	<td colspan="6"><input name="display" value="0" size="55" maxlength="55"></td>
	<td><input type="button" d="display" value="X"></td> <!--  reset  display -->
	<td><input type="button" d="display" value="<"></td> <!-- deleteChar -->
	<td><input name="enter" type="button" value="="></td> <!-- ENTER -->

	<td colspan="3"><input name="result" size="20" maxlength="20"></td>
	<td><input type="button" d="result" value="X"></td> <!-- reset -->
	<td><input type="button" d="result" value="<"></td> <!--  delete char-->
	<td><input type="button" d="result" value="№"></td> <!-- sqrt -->
	<td><input type="button" d="result" value="^2"></td> <!-- square -->
	<td><input type="button" d="result" value="exp"></td> <!-- exp -->

</tr>

<tr>
 
	<td><input type="button" value="*"></td> <!-- addChar -->
	<td><input type="button" value="-"></td>  <!-- addChar -->
	<td><input type="button" value="/"></td>  <!-- addChar -->
	<td><input type="button" value="+/-"></td> <!-- changeSign -->
	<td><input type="button" value="+"></td>  <!-- addChar -->
	<td><input type="button" value="("></td>   <!-- addChar -->
	<td><input type="button" value=")"></td>   <!-- addChar -->
	<td><input type="button" value="ln"></td>
	<td><input type="button" value="cos"></td>
	<td><input type="button" value="sin"></td>
	<td><input type="button" value="tan"></td>
	
</tr>

</tbody></table>
</form>


<script>

var MegaCalc= new function(){

	var 
	D=document,
	form=D.getElementById('form-mega-calc'),
	fres=form.result,
	fdisp=form.display,
	
	M=function(n){
		if(['cos','sin','tan','sqrt','ln','exp'].indexOf(n)>-1)
			return fres.value = Math[n](fdisp.value);
		else if(n=='sqrt')
			return fres.value = eval(fdisp.value)*eval(fdisp.value);
	},
	
	delChar=function(el){
		el.value=el.value.substring(0,el.value.length-1);
	},
	
	chSign=function(el) {
		if(el.value.substring(0, 1) == "-")
			el.value = el.value.substring(1, el.value.length);
		else
			el.value = "-" + el.value;
	},

	checkNum=function(str) {

		for (var ch, i=0; i<str.length; i++) {
		
			ch=str.substring(i,i+1);
			
			if ((ch < 0 || ch > 9) && '/*+-.()'.indexOf(ch)==-1)
				return false

		}
		
		return true;
	},
	
	compute=function() {
		fres.value=eval(fdisp.value);
	},
	
	route=function(e){
		var el=e.target,v,d;
		if(el.type && el.type=='button'){
			v=el.value;
			d=el.getAttribute('d');
			/* todo */
			if(!M(v))
				fdisp.value+=v;
		}
	};

	form.addEventListener('click',route);
	
};

</script>

</body>
</html>
Ответить с цитированием