加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

如何在HTML正文中调用JavaScript函数

发布时间:2020-12-14 21:13:43 所属栏目:资源 来源:网络整理
导读:我有一个填充表格的JavaScript函数: scriptvar col1 = ["Full time student checking (Age 22 and under) ","Customers over age 65","Below $500.00"];var col2 = ["None","None","$8.00"];function createtable() { !--To fill the table with javascript
我有一个填充表格的JavaScript函数:
<script>

var col1 = ["Full time student checking (Age 22 and under) ","Customers over age 65","Below  $500.00"];
var col2 = ["None","None","$8.00"];

function createtable() {
    <!--To fill the table with javascript-->
    for (var j = 0; j < col1.length; j++) {
        if (j % 2 == 0) {
            document.write("<tr><td>" + col1[j] + " </td>");
            document.write("<td>" + col2[j] + "</td></tr>");
        } else {
            document.write("<tr  bgcolor='#aeb2bf'><td>" + col1[j] + " </td>");
            document.write("<td>" + col2[j] + "</td></tr1>");
        }
    }
}
</script>

我想在HTML正文中执行它.我尝试了以下,但它没有创建表.

<table>
    <tr>
        <th>Balance</th>
        <th>Fee</th>        
    </tr>
      createtable();
</table>

我如何在HTML体内执行此功能?

解决方法

尝试包装createtable(); < script>中的语句标签:
<table>
        <tr>
            <th>Balance</th>
            <th>Fee</th>

        </tr>
        <script>createtable();</script>
</table>

如果我是你,我会避免使用document.write()并使用DOM.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读