<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>