如何使用JavaScript在带有ID的td中插入文本 [英] How to insert text in a td with id, using JavaScript
本文介绍了如何使用JavaScript在带有ID的td中插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这可能是一件简单的事情,但我无法弄清楚。我试图将来自JavaScript函数onload事件的文本插入到td中。
< html>
< head>
< script type =text / javascript>
函数insertText()
{
//函数在td上插入任何带有IDtd1的文本
}
< / script>
< / head>
< body onload =javascript:insertText()>
< table>
< tr>
< td id =td1>
< / td>
< / tr>
< / table>
< / body>
< / html>
任何帮助?
解决方案
< HTML>
< head>
< script type =text / javascript>
函数insertText(){
document.getElementById('td1')。innerHTML =要输入的文本;
}
< / script>
< / head>
< body onload =insertText();>
< table>
< tr>
< td id =td1>< / td>
< / tr>
< / table>
< / body>
< / html>
I know it may be a simple thing, but I can't figure out. I am trying to insert some text coming from a JavaScript function onload event into a td.
<html>
<head>
<script type="text/javascript">
function insertText ()
{
//function to insert any text on the td with id "td1"
}
</script>
</head>
<body onload="javascript:insertText()">
<table>
<tr>
<td id="td1">
</td>
</tr>
</table>
</body>
</html>
Any help?
解决方案
<html>
<head>
<script type="text/javascript">
function insertText () {
document.getElementById('td1').innerHTML = "Some text to enter";
}
</script>
</head>
<body onload="insertText();">
<table>
<tr>
<td id="td1"></td>
</tr>
</table>
</body>
</html>
这篇关于如何使用JavaScript在带有ID的td中插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文