怎样把js里的结果写到html的文本中 在线等
HTML部分代码<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>t...
HTML部分代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<br /><br /><br /><br /><br /><br /><br /><br />
<form onsubmit="mytest(this.form)">
<table align="center">
<tr><td>
请输入生日:</td><td><input type="text" name="mytext" size="2" onchange="getmytext(this)">月<input type="text" name="mytext01" size="2" onchange="getmytext2(this)">日</td></tr>
<tr><td>
您的星座为:</td><td><input type="text" name="result" id="result" size="8"></td></tr>
<tr><td>
您的运势为:</td><td>
<textarea rows="12" cols="50" name="result01" id="result01" style="display: none"></textarea>
</td></tr>
<tr><td>
<input type="submit" value="提交"></td><td>
<input type="button" value="重置" onclick="window.location('test.html')"></td></tr>
</table>
</form>
</body>
</html>
JS部分代码
var mytext01;
var mytext;
function getmytext(num){
mytext=num;
}
function getmytext2(num){
mytext01=num;
}
function mytest(form){
var m=null;
m =mytext01;
if(mytext == "" || mytext == null || mytext == 0 || mytext01 == "" || mytext01 == null || mytext01 == 0){
alert("please input a right munth");
return false;
}
else{
if(m < 10){
m="0"+mytext01;
}
var n=mytext+m;
}
var result=null;
var result01=document.getElementById("result");
var result02=document.getElementById("result01");
var b=null;
var c=null;
result02.style.display="";
if((n>1122 && n<=1130)||(n>1200 && n<1222)){
b="射手座";
result01.value = b;
result02.value = "8月。运势较差的月份是,2009/9月,2009/10月中旬前,2010/1月,4月,5月,9月,10月。";
}else{
var c='怪物';
result01.value = c;
result02.value = "请输入正确生日!";
}
} 展开
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<br /><br /><br /><br /><br /><br /><br /><br />
<form onsubmit="mytest(this.form)">
<table align="center">
<tr><td>
请输入生日:</td><td><input type="text" name="mytext" size="2" onchange="getmytext(this)">月<input type="text" name="mytext01" size="2" onchange="getmytext2(this)">日</td></tr>
<tr><td>
您的星座为:</td><td><input type="text" name="result" id="result" size="8"></td></tr>
<tr><td>
您的运势为:</td><td>
<textarea rows="12" cols="50" name="result01" id="result01" style="display: none"></textarea>
</td></tr>
<tr><td>
<input type="submit" value="提交"></td><td>
<input type="button" value="重置" onclick="window.location('test.html')"></td></tr>
</table>
</form>
</body>
</html>
JS部分代码
var mytext01;
var mytext;
function getmytext(num){
mytext=num;
}
function getmytext2(num){
mytext01=num;
}
function mytest(form){
var m=null;
m =mytext01;
if(mytext == "" || mytext == null || mytext == 0 || mytext01 == "" || mytext01 == null || mytext01 == 0){
alert("please input a right munth");
return false;
}
else{
if(m < 10){
m="0"+mytext01;
}
var n=mytext+m;
}
var result=null;
var result01=document.getElementById("result");
var result02=document.getElementById("result01");
var b=null;
var c=null;
result02.style.display="";
if((n>1122 && n<=1130)||(n>1200 && n<1222)){
b="射手座";
result01.value = b;
result02.value = "8月。运势较差的月份是,2009/9月,2009/10月中旬前,2010/1月,4月,5月,9月,10月。";
}else{
var c='怪物';
result01.value = c;
result02.value = "请输入正确生日!";
}
} 展开
2个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<table align="center">
<tr><td>
请输入生日:</td><td><input id="t_month" type="text" name="mytext" size="2">月
<input id="t_day" type="text" name="mytext01" size="2">日</td></tr>
<tr><td>
您的星座为:</td><td><input type="text" name="result" id="result" size="8"></td></tr>
<tr><td>
您的运势为:</td><td>
<textarea rows="12" cols="50" name="result01" id="result01" style="display: none"></textarea>
</td></tr>
<tr><td>
<input type="button" value="提交" onclick="mytest()"></td><td>
<input type="button" value="重置" onclick="javascript:window.refresh();"></td></tr>
</table>
</body>
</html>
test.js.
==============================================================
function mytest(){
var m = document.getElementById("t_month").value;
var d = document.getElementById("t_day").value;
//判断月份输入是否合法.
if(!isNaN(m)){
if((m/1)>12 && (m/1) <= 0) {
document.getElementById("t_month").value = "";
document.getElementById("t_month").focus();
alert("请输入1到12之间的数字");
return;
}
}else{
document.getElementById("t_month").value = "";
document.getElementById("t_month").focus();
alert("请输入1到12之间的数字");
return;
}
//判断天数输入是否合法.
//.......条件很多..我就不写了.
//存储各个星座日期的分界日期的日数
//var splits = ["1.20","2.19","3.21","4.20","5.21","6.22","7.23","8.23","9.23","10.24","11.23","12.22"];
var splits = ["20","19","21","20","21","22","23","23","23","24","23","22"];
var s_d = splits[m-1];
//因为每个月只有一个分界日期.所以可以直接比较月份.
if(((m/1) == 11 && (s_d/1) <= (d/1)) || ((m/1) == 12 && (s_d/1) > (d/1))){
document.getElementById("result").value = '射手座';
document.getElementById("result01").value = "8月。运势较差的月份是,2009/9月,2009/10月中旬前,2010/1月,4月,5月,9月,10月。";
document.getElementById("result01").style.display = "";
}else{
document.getElementById("result").value = '天使座';
document.getElementById("result01").style.display = "none";
}
}
<html>
<head>
<title>test.html</title>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<table align="center">
<tr><td>
请输入生日:</td><td><input id="t_month" type="text" name="mytext" size="2">月
<input id="t_day" type="text" name="mytext01" size="2">日</td></tr>
<tr><td>
您的星座为:</td><td><input type="text" name="result" id="result" size="8"></td></tr>
<tr><td>
您的运势为:</td><td>
<textarea rows="12" cols="50" name="result01" id="result01" style="display: none"></textarea>
</td></tr>
<tr><td>
<input type="button" value="提交" onclick="mytest()"></td><td>
<input type="button" value="重置" onclick="javascript:window.refresh();"></td></tr>
</table>
</body>
</html>
test.js.
==============================================================
function mytest(){
var m = document.getElementById("t_month").value;
var d = document.getElementById("t_day").value;
//判断月份输入是否合法.
if(!isNaN(m)){
if((m/1)>12 && (m/1) <= 0) {
document.getElementById("t_month").value = "";
document.getElementById("t_month").focus();
alert("请输入1到12之间的数字");
return;
}
}else{
document.getElementById("t_month").value = "";
document.getElementById("t_month").focus();
alert("请输入1到12之间的数字");
return;
}
//判断天数输入是否合法.
//.......条件很多..我就不写了.
//存储各个星座日期的分界日期的日数
//var splits = ["1.20","2.19","3.21","4.20","5.21","6.22","7.23","8.23","9.23","10.24","11.23","12.22"];
var splits = ["20","19","21","20","21","22","23","23","23","24","23","22"];
var s_d = splits[m-1];
//因为每个月只有一个分界日期.所以可以直接比较月份.
if(((m/1) == 11 && (s_d/1) <= (d/1)) || ((m/1) == 12 && (s_d/1) > (d/1))){
document.getElementById("result").value = '射手座';
document.getElementById("result01").value = "8月。运势较差的月份是,2009/9月,2009/10月中旬前,2010/1月,4月,5月,9月,10月。";
document.getElementById("result01").style.display = "";
}else{
document.getElementById("result").value = '天使座';
document.getElementById("result01").style.display = "none";
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询