使用JavaScript 编写简单计算器,javascript计算器

by admin on 2020年1月22日

<html>
<head>
澳门新葡亰平台官网,<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>网页特效|网页特效代码(JsHtml.cn卡塔尔国—普通计算器代码</title>
</head>
<body>
<script language=”JavaScript”>
<!– Hide the script from
old browsers —
function compute(obj)
   {obj.expr.value =
eval(obj.expr.value)}
var one = ‘1’
var two = ‘2’
var three = ‘3’
var four = ‘4’
var five = ‘5’
var six = ‘6’
var seven = ‘7’
var eight = ‘8’
var nine = ‘9’
var zero = ‘0’
var plus = ‘+’
var minus = ‘-‘
var multiply = ‘*’
var divide = ‘/’
var decimal = ‘.’
function enter(obj, string)
   {obj.expr.value += string}
function clear(obj)
   {obj.expr.value = ”}
// –End Hiding Here
–>
</script>
<form name=”calc”>
<table border=1>
<td
colspan=4><input
type=”text”
name=”expr” size=30
action=”compute(this.form)”> <tr>
<td><input
type=”button”
value=”  7  ” onClick=”enter(this.form, seven)”>
<td><input
type=”button”
value=”  8  ” onClick=”enter(this.form, eight)”>
<td><input
type=”button”
value=”  9  ” onClick=”enter(this.form, nine)”>
<td><input
type=”button”
value=”   /  ” onClick=”enter(this.form, divide)”>
<tr><td><input
type=”button”
value=”  4  ” onClick=”enter(this.form, four)”>
<td><input
type=”button”
value=”  5  ” onClick=”enter(this.form, five)”>
<td><input
type=”button”
value=”  6  ” onClick=”enter(this.form, six)”>
<td><input
type=”button”
value=”  *  ” onClick=”enter(this.form, multiply)”>
<tr><td><input
type=”button”
value=”  1  ” onClick=”enter(this.form, one)”>
<td><input
type=”button”
value=”  2  ” onClick=”enter(this.form, two)”>
<td><input
type=”button”
value=”  3  ” onClick=”enter(this.form, three)”>
<td><input
type=”button”
value=”   –  ” onClick=”enter(this.form, minus)”>
<tr><td
colspan=2><input
type=”button”
value=”       0       ” onClick=”enter(this.form, zero)”>
<td><input
type=”button”
value=”   .  ” onClick=”enter(this.form, decimal)”>
<td><input
type=”button”
value=”  +  ” onClick=”enter(this.form, plus)”>
<tr><td
colspan=2><input
type=”button”
value=”   =   ” onClick=”compute(this.form)”>
<td
colspan=2><input
type=”button”
value=”AC” size= 3
onClick=”clear(this.form)”> </table>
</form>

选拔JavaScript 编写轻易总结器,javascript总括器

正文方法一级简单,思路特别的值得推荐,小友人们参照他事他说加以考察下啊

复制代码 代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″
/> 
    <title>javascript 轻巧计算器</title>
    <script>
        //定义全局变量         var one=”1″;
        var two=”2″;
        var three=”3″;
        var four=”4″;
        var five=”5″;
        var six=”6″;
        var seven=”7″;
        var eight=”8″;
        var nine=”9″;
        var zero=”0″;
         var plus=”+”,minus=”-“,multiply=”*”,divide=”/”,decimal=”.”;
         function enter(obj,string){
                obj.expr.value+=string;
            }
         function
compute(obj卡塔尔(قطر‎{//单击等于”=”开关调用的函数;                 
obj.expr.value=eval(obj.expr.value卡塔尔;//用JS得eval(State of Qatar方法总结name为expr中的公式             
}
  </script>
</head>
<body>
    <form name=”calc” id=”calc” action=””> 
        <table border=”1″> 
        <td colspan=”4″><input type=”text” name=”expr”
size=”30″ action=”compute(this.form)” /></td> 
        <tr> 
        <td><input type=”button” value=” 7 ”
onclick=”enter(this.form,seven)” /></td> 
        <td><input type=”button” value=” 8 ”
onclick=”enter(this.form,eight)” /></td> 
        <td><input type=”button” value=” 9 ”
onclick=”enter(this.form,nine)” /></td> 
        <td><input type=”button” value=” / ”
onclick=”enter(this.form,divide)” /></td> 
        </tr> 
        <tr> 
        <td><input type=”button” value=” 4 ”
onclick=”enter(this.form,four)” /></td> 
        <td><input type=”button” value=” 5 ”
onclick=”enter(this.form,five)” /></td> 
        <td><input type=”button” value=” 6 ”
onclick=”enter(this.form,six)” /></td> 
        <td><input type=”button” value=” * ”
onclick=”enter(this.form,multiply)” /></td> 
        </tr> 
        <tr> 
        <td><input type=”button” value=” 1 ”
onclick=”enter(this.form,one)” /></td> 
        <td><input type=”button” value=” 2 ”
onclick=”enter(this.form,two)” /></td> 
        <td><input type=”button” value=” 3 ”
onclick=”enter(this.form,three)” /></td> 
        <td><input type=”button” value=” – ”
onclick=”enter(this.form,minus)” /></td> 
        </tr> 
        <tr> 
        <td colspan=”2″><input type=”button” value=” 0 ”
onclick=”enter(this.form,zero)” /></td> 
        <td><input type=”button” value=” . ”
onclick=”enter(this.form,decimal)” /></td> 
        <td><input type=”button” value=” + ”
onclick=”enter(this.form,plus)” /></td> 
        </tr> 
        <tr> 
        <td colspan=”2″><input type=”button” value=” = ”
onclick=”compute(this.form)” /></td> 
        <td colspan=”2″><input type=”button” value=”AC”
onclick=”form.reset()”/></td> 
        </tr> 
        </table> 
</form> 
</body>
</html>

是否超级NB的代码,大神级的!

编写轻巧总结器,javascript总括器
本文方法一流简单,思路十三分的值得推荐,小朋侪们参谋下吧 复制代码
代码如下: !DOCTYPE h…

方今因项目须求整合治理了个jquery 编辑table tr实例  直接上代码……
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“;

</body>
</html>

<!– saved from
url=(0059)
–>
<HTML xmlns=”;
<TITLE>js操作刷新</TITLE>
<META http-equiv=Content-Type content=”text/html;
charset=utf-8″;>
<META content=360doc name=classification>
<META content=js操作刷新 name=keywords>
<META content=js操作刷新 name=description>
<script src=”jquery.js” type=”text/javascript”></script>
<body>
<h1>实例1</h1>
<table cellpadding=”2″ cellspacing=”2″ border=”1″ width=”80%”>
<tr>
<td>所属体系</td>
<td>最小值</td>
<td>最大值</td>
<td> </td>
</tr>
<tr>
<td>类别1</td>
<td>2</td>
<td>10</td>
<td id=”1″><input type=”button” onClick=”edit(this)”
value=”修改”/></td>
</tr>
<tr>
<td>类别2</td>
<td>5</td>
<td>100</td>
<td id=”2″><input type=”button” onClick=”edit(this)”
value=”修改”/></td>
</tr>
</table>

<script type=”text/javascript”>
function edit(obj){
    var old0=$(obj).parent().prevAll(“:eq(0)”).text();
    var old1=$(obj).parent().prevAll(“:eq(1)”).text();
   
$(obj卡塔尔(قطر‎.parent(State of Qatar.prevAll(“:eq(0卡塔尔国”State of Qatar.data(“oldtxt”,old0卡塔尔;//将单元格最早的文章本保存在其缓存中,便改进战败或裁撤时用
    $(obj).parent().prevAll(“:eq(1)”).data(“oldtxt”,old1);
    $(obj).parent().prevAll(“:eq(0)”).html(“<input type=’text’
value='”+old0+”‘”);
    $(obj).parent().prevAll(“:eq(1)”).html(“<input type=’text’
value='”+old1+”‘”);
    $(obj).parent().append(” <input type=’button’
onClick=’cancel(this)’ value=’取消’/>”);
    $(obj).attr(“value”,”保存”);
    $(obj).attr(“onClick”,”save(this)”);
}

function save(obj){
    var id=$(obj).parent().attr(“id”);  //id
    var category=$(obj).parent().prevAll(“:eq(2)”).text(); //类别
    var min=$(obj).parent().prevAll(“:eq(1)”).children().val().trim();
//默认值
    var max=$(obj).parent().prevAll(“:eq(0)”).children().val().trim();
//最大值
    jQuery.ajax({
        type : ‘POST’,
        url     : ‘<%=basePath%>/test.do?method=modify’,
        data : ‘id=’+id+’&category=’+category+’&min=’+min+’&max=’+max,
        dataType : ‘json’,
        success : function(rs){
            if(rs.success){
                $(obj).parent().prevAll(“:eq(1)”).html(min);
                $(obj).parent().prevAll(“:eq(0)”).html(max);
                $(obj).parent().html(“<input type=’button’
onClick=’edit(this)’ value=’修改’/>”);
            }else{
                jAlert(errorTitle,’失败’,true);
                cancel(obj); //取消
            }
        }
    });
}

function cancel(obj){
    var
old0=$(objState of Qatar.parent(State of Qatar.prevAll(“:eq(0卡塔尔(قطر‎”卡塔尔(قطر‎.data(“oldtxt”卡塔尔国;//将单元格内容设为原始数据
    var old1=$(obj).parent().prevAll(“:eq(1)”).data(“oldtxt”);
    $(obj).parent().prevAll(“:eq(0)”).html(old0);
    $(obj).parent().prevAll(“:eq(1)”).html(old1);
    $(obj).parent().html(“<input type=’button’ onClick=’edit(this)’
value=’修改’/>”);
}
</script>
</body></html>

摘自 spring_0534的专栏

编辑table tr实例
直接上代码…… !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01
Transitional//EN …

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图