将 JavaScript 结果打印到两个 DIV 而不是输入中
Print JavaScript results into two DIVs instead of Inputs
大家晚上好,
我想创建一个从出生日期计算占星术标志的函数,在两个不同的 DIV 中打印结果。到目前为止,我只能将它们打印成两个输入,如下所示:
<head>
<script language="javascript">
function signs() {
var start = 1901, birthyear = "2000", date = "04", month = "05";
with (document.zodiac.sign){
if ((month == 1 || month == 01) && date >=20 || (month == 2 || month == 02) && date <=18) {value = "♒ Verseau";}
if ((month == 1 || month == 01) && date > 31) {value = "Cette date n'existe pas.";}
if ((month == 2 || month == 02) && date >=19 || (month == 3 || month == 03) && date <=20) {value = "♓ Poisson";}
if ((month == 2 || month == 02) && date > 29) {value = "Cette date n'existe pas.";}
if ((month == 3 || month == 03) && date >=21 || (month == 4 || month == 04) && date <=19) {value = "♈ Bélier";}
if ((month == 3 || month == 03) && date > 31) {value = "Cette date n'existe pas.";}
if ((month == 4 || month == 04) && date >=20 || (month == 5 || month == 05) && date <=20) {value = "♉ Taureau";}
if ((month == 4 || month == 04) && date > 30) {value = "Cette date n'existe pas.";}
if ((month == 5 || month == 05) && date >=21 || (month == 6 || month == 06) && date <=21) {value = "♊ Gémeaux";}
if ((month == 5 || month == 05) && date > 31) {value = "Cette date n'existe pas.";}
if ((month == 6 || month == 06) && date >=22 || (month == 7 || month == 07) && date <=22) {value = "♋ Cancer";}
if ((month == 6 || month == 06) && date > 30) {value = "Cette date n'existe pas.";}
if ((month == 7 || month == 07) && date >=23 || (month == 8 || month == 08) && date <=22) {value = "♌ Lion";}
if ((month == 7 || month == 07) && date > 31) {value = "Cette date n'existe pas.";}
if ((month == 8 || month == 08) && date >=23 || (month == 9 || month == 09) && date <=22) {value = "♍ Vierge";}
if ((month == 8 || month == 08) && date > 31) {value = "Cette date n'existe pas.";}
if ((month == 9 || month == 09) && date >=23 || month == 10 && date <=22) {value = "♎ Balance";}
if ((month == 9 || month == 09) && date > 30) {value = "Cette date n'existe pas.";}
if (month == 10 && date >=23 || month == 11 && date <=21) {value = "♏ Scorpion";}
if (month == 10 && date > 31) {value = "Cette date n'existe pas.";}
if (month == 11 && date >=22 || month == 12 && date <=21) {value = "♐ Sagittaire";}
if (month == 11 && date > 30) {value = "Cette date n'existe pas.";}
if (month == 12 && date >=22 || (month == 1 || month == 01) && date <=19) {value = "♑ Capricorne";}
if (month == 12 && date > 31) {value = "Cette date n'existe pas.";}
}
x = (start - birthyear) % 12
with (document.zodiac.csign){
if (x == 1 || x == -11) {value = "鼠 Rat";}
if (x == 0) {value = "牛 Bœuf";}
if (x == 11 || x == -1) {value = "兎 Tigre";}
if (x == 10 || x == -2) {value = "兔 Lapin";}
if (x == 9 || x == -3) {value = "龍 Dragon";}
if (x == 8 || x == -4) {value ="蛇 Serpent";}
if (x == 7 || x == -5) {value = "馬 Cheval";}
if (x == 6 || x == -6) {value = "羊 Mouton";}
if (x == 5 || x == -7) {value = "猴 Singe";}
if (x == 4 || x == -8) {value = "雞 Coq";}
if (x == 3 || x == -9) {value = "狗 Chien";}
if (x == 2 || x == -10) {value = "豬 Cochon";}
}
}
</script>
</head>
<body onload="signs()">
<form name="zodiac">
<table>
<tr>
<td>Signe astrologique chinois :</td>
<td><input type="text" name="csign" size="12"></td>
</tr>
<tr>
<td>Signe du zodiaque :</td>
<td><input type="text" name="sign" size="12" value="" align="right"></td>
</tr>
</table>
</form>
</body>
我尝试创建新的 DIV 而不是输入,并在符号和 csign(第 6 行和第 33 行)之后添加 innerHTML,但它不起作用。
谁能帮我找到如何进行?提前谢谢你!
不要使用 with
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with
通过 id 访问您的div。
http://jsfiddle.net/ymeejLzb/
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- 使用Javascript对象为具有两个背景图像的DIV设置样式时出现问题
- 同时换掉两个Div,换成另一个Div并保持循环一段固定的秒数
- 从iframe中选择具有相同类名的两个DIV中的第二个
- 使用两个或多个按钮在单个DIV中显示/隐藏和替换文本
- CSS/Javascript/Jquery:显示/隐藏 DIV 取决于单击的两个图像之一
- 将 JavaScript 结果打印到两个 DIV 而不是输入中
- 如何访问相同索引级别但位于不同父DIV中的两个元素
- 在两个Div之间切换
- 如何在Javascript中更改两个或多个Div样式
- 使用JQuery添加两个DIV
- 如何使同步两个 Div 滚动位置更平滑
- Javascript:两个Div ID's中的元素
- 基本Js函数缩放两个DIV's高度
- 在左右浮动两个Div后,下一个Div不能正确显示
- 如果选中两个特定复选框,则显示DIV;如果只选中一个复选框,显示不同的DIV
- 如何使用 Jquery 根据 ID 在两个 Div 之间附加一个 Div
- 使用jquery在两个Div's之间切换