Показать сообщение отдельно
  #3 (permalink)  
Старый 06.10.2016, 15:10
Интересующийся
Отправить личное сообщение для svinin_1989 Посмотреть профиль Найти все сообщения от svinin_1989
 
Регистрация: 03.10.2016
Сообщений: 11

Вот страничка с калькулятором, хочу убрать кнопку = вобще.
Чтоб решение появлялось во время набора цифр
<!DOCTYPE HTML>
<html>
  <head> </head>
  <body>
 <font color="RED" size="18"> <B>КАЛЬКУЛЯТОР</B></font> <br/>
<form name="sci-calc">
<table table border="1"  >
<tbody> 
<tr>
<td align="center" style="background-color: red"  ><input type="button" value="1" onclick="addChar(this.form.display, &#39;1&#39;) "></td>
<td align="center"  ><input type="button" value="2" onclick="addChar(this.form.display, &#39;2&#39;)"></td>
<td align="center"  ><input type="button" value="3" onclick="addChar(this.form.display, &#39;3&#39;)"></td>
<td align="center"  ><input type="button" value="4" onclick="addChar(this.form.display, &#39;4&#39;)"></td>
<td align="center"  ><input type="button" value="5" onclick="addChar(this.form.display, &#39;5&#39;)"></td>
<td align="center"  ><input type="button" value="6" onclick="addChar(this.form.display, &#39;6&#39;)"></td>
<td align="center"><input type="button" value="7" onclick="addChar(this.form.display, &#39;7&#39;)"></td>
<td align="center"><input type="button" value="8" onclick="addChar(this.form.display, &#39;8&#39;)"></td>
<td align="center"><input type="button" value="9" onclick="addChar(this.form.display, &#39;9&#39;)"></td>
<td align="center"><input type="button" value="0" onclick="addChar(this.form.display, &#39;0&#39;)"></td>
<td align="center"><input type="button" value="." onclick="addChar(this.form.display, &#39;.&#39;)"></td>
</tr>
 


<tr>
<td colspan="6" align="center"><input name="display" value="0" size="55" maxlength="55"></td>
<td align="center"><input type="button" value="X" onclick="this.form.display.value = 0 "></td>
<td align="center"  ><input type="button" value="<" onclick="deleteChar(this.form.display)"></td>

<td align="center"><input type="button" value="=" name="enter" onclick="if (checkNum(this.form.display.value)) { compute(this.form) }"></td>

 <td colspan="3" align="center"><input name="result"   size="20" maxlength="20"></td>
<td align="center"><input type="button" value="X" onclick="this.form.result.value = 0 "></td>
<td align="center"  ><input type="button" value="<" onclick="deleteChar(this.form.result)"></td>
<td align="center"><input type="button" value="№" onclick="if (checkNum(this.form.display.value)) { sqrt(this.form) }"></td>
<td align="center"><input type="button" value="^2" onclick="if (checkNum(this.form.display.value)) { square(this.form) }"></td>
<td align="center"><input type="button" value="exp" onclick="if (checkNum(this.form.display.value)) { exp(this.form) }"></td>

</tr>


<tr>
 
<td align="center"><input type="button" value="*" onclick="addChar(this.form.display, &#39;*&#39;)"></td>
<td align="center"><input type="button" value="-" onclick="addChar(this.form.display, &#39;-&#39;)"></td>
  
<td align="center"><input type="button" value="/" onclick="addChar(this.form.display, &#39;/&#39;)"></td>
<td align="center"><input type="button" value="+/-" onclick="changeSign(this.form.display)"></td>
<td align="center"><input type="button" value="+" onclick="addChar(this.form.display, &#39;+&#39;)"></td>

 
<td align="center"><input type="button" value="(" onclick="addChar(this.form.display, &#39;(&#39;)"></td>
<td align="center"><input type="button" value=")" onclick="addChar(this.form.display, &#39;)&#39;)"></td>

<td align="center"><input type="button" value="ln" onclick="if (checkNum(this.form.display.value)) { ln(this.form) }"></td>
 
<td align="center"><input type="button" value="cos" onclick="if (checkNum(this.form.display.value)) { cos(this.form) }"></td>
<td align="center"><input type="button" value="sin" onclick="if (checkNum(this.form.display.value)) { sin(this.form) }"></td>
<td align="center"><input type="button" value="tan" onclick="if (checkNum(this.form.display.value)) { tan(this.form) }"></td>
 </tr>

</tbody></table>
</form>
    <script>
	
	
	element.addEventListener('click',compute(form));

function addChar(input, character) {
  
 
	if(input.value == null || input.value == "0")
		input.value = character;
 
	else
		input.value += character;
	 
	  
  
	}
 
 

function cos(form) {
	form.result.value = Math.cos(form.display.value);
}

function sin(form) {
	form.result.value = Math.sin(form.display.value);
}

function tan(form) {
	form.result.value = Math.tan(form.display.value);
}

function sqrt(form) {
	form.result.value = Math.sqrt(form.display.value);
}

function ln(form) {
	form.result.value = Math.log(form.display.value);
}

function exp(form) {
	form.result.value = Math.exp(form.display.value);
}

function deleteChar(input) {
	input.value = input.value.substring(0, input.value.length - 1)
}

function changeSign(input) {
	if(input.value.substring(0, 1) == "-")
		input.value = input.value.substring(1, input.value.length)
	else
		input.value = "-" + input.value
}

    function compute(form) {
 form.result.value = eval(form.display.value)
}
 

 
 

function square(form) {
	form.result.value = eval(form.display.value) * eval(form.display.value)
}

function checkNum(str) {
	for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i+1)
		if (ch < "0" || ch > "9") {
			if (ch != "/" && ch != "*" && ch != "+" && ch != "-" && ch != "."
				&& ch != "(" && ch!= ")") {
				alert("invalid entry!")
				return false
				}
			}
		}
		return true
}

    </script>

  </body>
</html>



Вешаю на elem.onclick = function compute(form) {
form.result.value = eval(form.display.value)
}
не срабатывает
Ответить с цитированием