首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

txt文本框的value能否使用四则运算?该如何解决

2012-05-29 
txt文本框的value能否使用四则运算?input nametextfield typetext value5+1 size5 /我想在

txt文本框的value能否使用四则运算?
<input name="textfield" type="text" value="5+1" size="5" />


我想在一个文本框中的值自动等于四则运算后的结果, 如上面显示的是值6,而不是5+1 ,
请问有办法吗?

[解决办法]

HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>        <style>                </style>    </head>    <body>        <input value="6+4" id="a" />        <button id="btn">计算</button>        <script>            var $ = function(id){                return document.getElementById(id);            };            $('btn').onclick= function(){                $('a').value = eval($('a').value);            }        </script>    </body></html> 

热点排行