<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table>
<tr>
<th id='v1'>5</th>
</tr>
</table>
<input type="text" id='v2'>
<input type="button" onclick="bj()" value="比较">
</body>
<script>
function bj () {
v1=document.getElementById('v1').innerHTML
v2=document.getElementById('v2').value
v=v1>v2?v1:v2//自己改 这里输出大的值
alert(v)
}
</script>
</html>
以下为代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题文档</title>
</head>
<body>
分子:
<input name="l1" type="text" id="l1" />
<br>
分母:
<input name="l2" type="text" id="l2" />
<br>
<input type="button" name="button" value="计算" onclick="ChkTpye()"/>
<script language="JavaScript" type="text/javascript">
function ChkTpye()
{
var o1 = document.getElementById("l1")
var o2 = document.getElementById("l2")
var v1 = parseInt(o1.value)
var v2 = parseInt(o2.value)
if ( isNaN(v1) )
{
alert('输入分子不是有效数字!')
o1.focus()
return
}
else
{
if ( v1 <= 0 || o1.value.indexOf(".") != -1 )
{
alert('输入分子数据不正确!')
o1.focus()
return
}
}
if ( isNaN(v2) )
{
alert('输入分母不是有效数字!')
o2.focus()
return
}
else
{
if ( v2 <= 0 || o2.value.indexOf(".") != -1 )
{
alert('输入分母的数据不正确!')
o2.focus()
return
}
}
var s1 = v1 / v2
var s2 = s1 * 100
alert(s2+"%")
}
</script>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)