2013-11-04 10 views
-2

我有一個asp.net內容頁面,我需要在裏面寫一個計算器(?)它。asp.net內容頁面上的javascript計算器。可能嗎?

<%@ Page Title="Calculator" Language="C#" AutoEventWireup="true" CodeBehind="Calculator.aspx.cs" Inherits="WebApplication2.Calculator" MasterPageFile="~/Site.Master" %> 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content> 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
<!-- calculator code here --> 
</asp:Content> 

我有一個HTML頁面一個簡單的JavaScript計算器:

<head> 
    <title></title> 
</head> 

<body> 

<script type="text/javascript"> 

    function addvalue(arg1) { 
     Calc.Input.value += arg1; 
    } 

</script> 

<form action="#" name="Calc"> 

<table style="width: 160px" border="2"> 
    <tr> 
     <td colspan="4"> 
      <input id="Text1" type="text" maxlength=16 name="Input" style="width:98%" /></td> 
    </tr> 
    <tr> 
     <td style="width: 40px"> 
      <input id="Button1" type="button" value="1" onclick="addvalue('1')" /></td> 
     <td style="width: 40px"> 
      <input id="Button2" type="button" value="2" onclick="addvalue('2')" /></td> 
     <td style="width: 40px"> 
      <input id="Button3" type="button" value="3" onclick="addvalue('3')" /></td> 
     <td> 
      <input id="Button7" type="button" value="+" onclick="addvalue(' + ')" /></td> 
    </tr> 
    <tr> 
     <td> 
      <input id="Button4" type="button" value="4" onclick="addvalue('4')" /></td> 
     <td> 
      <input id="Button5" type="button" value="5" onclick="addvalue('5')" /></td> 
     <td> 
      <input id="Button6" type="button" value="6" onclick="addvalue('6')" /></td> 
     <td> 
      <input id="Button8" type="button" value="-" onclick="addvalue(' - ')" /></td> 
    </tr> 
    <tr> 
     <td> 
      <input id="Button9" type="button" value="7" onclick="addvalue('7')" /></td> 
     <td> 
      <input id="Button10" type="button" value="8" onclick="addvalue('8')" /></td> 
     <td> 
      <input id="Button11" type="button" value="9" onclick="addvalue('9')" /></td> 
     <td> 
      <input id="Button12" type="button" value="*" onclick="addvalue('*')" /></td> 
    </tr> 
    <tr> 
     <td> 
      <input id="Button13" type="button" value="C" onclick="Calc.Input.value=null" /></td> 
     <td> 
      <input id="Button14" type="button" value="0" onclick="addvalue('0')" /></td> 
     <td> 
      <input id="Button15" type="button" value="=" onclick="Calc.Input.value = eval(Calc.Input.value)" /></td> 
     <td> 
      <input id="Button16" type="button" value="/" onclick="addvalue('/')" /></td> 
    </tr> 
</table> 

</form> 

</body> 
</html> 

我需要適應這個代碼與一個asp.net頁面內容使用。我該怎麼做 ?

我知道asp.net是服務器端技術,JavaScript是客戶端。但我不知道如何使用一個內部的另一= \

+1

當然可以,你嘗試過什麼? –

+0

mcpDESIGNS,我需要將此js代碼移至asp.net。我不能'得到一個工作代碼不幸.. –

回答

1

是的,它是可能的,只是把裏面的內容JSJquery腳本的外觀下面的代碼:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
<table style="width: 160px" border="2"> 
    <tr> 
     <td colspan="4"> 
      <input id="Text1" type="text" maxlength=16 name="Input" style="width:98%" /></td> 
    </tr> 
    <tr> 
     <td style="width: 40px"> 
      <input id="Button1" type="button" value="1" onclick="addvalue('1')" /></td> 
     <td style="width: 40px"> 
      <input id="Button2" type="button" value="2" onclick="addvalue('2')" /></td> 
     <td style="width: 40px"> 
      <input id="Button3" type="button" value="3" onclick="addvalue('3')" /></td> 
     <td> 
      <input id="Button7" type="button" value="+" onclick="addvalue(' + ')" /></td> 
    </tr> 
    <tr> 
     <td> 
      <input id="Button4" type="button" value="4" onclick="addvalue('4')" /></td> 
     <td> 
      <input id="Button5" type="button" value="5" onclick="addvalue('5')" /></td> 
     <td> 
      <input id="Button6" type="button" value="6" onclick="addvalue('6')" /></td> 
     <td> 
      <input id="Button8" type="button" value="-" onclick="addvalue(' - ')" /></td> 
    </tr> 
    <tr> 
     <td> 
      <input id="Button9" type="button" value="7" onclick="addvalue('7')" /></td> 
     <td> 
      <input id="Button10" type="button" value="8" onclick="addvalue('8')" /></td> 
     <td> 
      <input id="Button11" type="button" value="9" onclick="addvalue('9')" /></td> 
     <td> 
      <input id="Button12" type="button" value="*" onclick="addvalue('*')" /></td> 
    </tr> 
    <tr> 
     <td> 
      <input id="Button13" type="button" value="C" onclick="Calc.Input.value=null" /></td> 
     <td> 
      <input id="Button14" type="button" value="0" onclick="addvalue('0')" /></td> 
     <td> 
      <input id="Button15" type="button" value="=" onclick="Calc.Input.value = eval(Calc.Input.value)" /></td> 
     <td> 
      <input id="Button16" type="button" value="/" onclick="addvalue('/')" /></td> 
    </tr> 
</table> 
<script type="text/javascript"> 

    function addvalue(arg1) { 
     Calc.Input.value += arg1; 
    } 

</script> 
</asp:Content> 

我希望幫助

+0

Freak_Droid,謝謝你的答案!它不幸的工作。我按下按鈕,輸入文本框中不顯示任何內容。 –

相關問題