如何使用Javascript在表div中编写 [英] How to write in a table div with Javascript

查看:73
本文介绍了如何使用Javascript在表div中编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var day = document.getElementById("day");
var holiday = new Date("October 30, 2012 12:55:00");





<table border="3px" align="center" style="border-color:black; border-style:solid; border-collapse:collapse; text-align:center;">
	<tr>
		<td width="100px";>days</td>
	</tr>
	<tr>
		<td id="day" width="100px";>here ist a space with html code (  ;)</td>
	</tr>
</table>



我该如何在ID天为id的表div中写上节假日?



How can I write in the table div with the id day the variable holiday?

推荐答案

看看这些链接:

http://stackoverflow.com/questions/4252130/passing-javascript-variable-to- html-textbox [ ^ ]

http://www.htmlgoodies. com/beyond/javascript/article.php/3471111/A-Quick-Tutorial-on-JavaScript-Variable-Passing.htm [ http: //www.daniweb.com/web-development/javascript-dhtml-ajax/threads/194344/retrieve-value-of-javascript-variable-to-html-table-cells [
Take a look at these links:

http://stackoverflow.com/questions/4252130/passing-javascript-variable-to-html-textbox[^]

http://www.htmlgoodies.com/beyond/javascript/article.php/3471111/A-Quick-Tutorial-on-JavaScript-Variable-Passing.htm[^]

http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/194344/retrieve-value-of-javascript-variable-to-html-table-cells[^]

All in all I''ve searched google using variable javascript to html.

Good luck.


您可以尝试以下操作:
You can try this:
document.getElementById("day").innerHTML = holiday;


另外,您可以在此处找到innerHTML
参考 [


Also, you can find innerHTML reference here[^]

Furthermore, if you don''t access the particular table cell in any other location, your can get rid of this whole line
var day = document.getElementById("day");


有关如何写入表格单元格的测试/演示(完整的HTML文档):

A test/demo for how to write to the table cell (full HTML doc):

<html>
  <head>
    <script type="text/javascript">
	  var day = document.getElementById("day");
	  var holiday = new Date("October 30, 2012 12:55:00");
			
	  function writeToField() {
	    document.getElementById("day").innerHTML = holiday.toString();
	  }
    </script>
  </head>
  
  <body>
    <table border="3px" align="center" style="border-color:black; border-style:solid; border-collapse:collapse; text-align:center;">
	  <tr>
	    <td width="100px">days</td>
	  </tr>
	  <tr>
	    <td id="day" width="100px"> </td>
	  </tr>
    </table>
		
    <input type="button" id="testButton" value="Test"  onclick="writeToField();">
  </input></body>
</html>


这篇关于如何使用Javascript在表div中编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆