SyntaxError:函数调用上的意外标记ILLEGAL

时间:2014-07-18 18:44:09

标签: javascript html

我知道这个错误通常来自哪个,但我无法在我的代码中找到它。我知道这是声明:

button.setAttribute("onclick", "makeUneditable(" + row_id + ")")

我已经包含了所有代码,因此您可以了解您正在查看的内容。只有fyi {{row}}是我用Jinja2传入然后在javascript中转换为字符串的列表。但我不确定该声明中的内容是非法的。有什么想法吗?

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <script>
        function makeEditable(row_id) {
            row_id = String(row_id)
            var row = document.getElementById(row_id); 
            row.setAttribute("contenteditable", "true")

            var button = document.getElementById(row_id+"_button"); 
            button.setAttribute("onclick", "makeUneditable(" + row_id + ")")
            button.innerHTML = "Done Editing";
        }

        function makeUneditable(row_id) {
            row_id = String(row_id)
            console.log(row_id)
            var row = document.getElementById(row_id); 
            row.setAttribute("contenteditable", "false")
        }

    </script>

</head> 
<body>


    <table class="TFtable" style="width:300px">
        <thead>
        {% for column_name in column_names %}
        <th>{{column_name}}</th>
        {% endfor %}
        </thead>
        {% for row in table %}
            <script>
                document.writeln('<tr id="' + String({{row}}) + '">');
            </script>
                {% for cell in row %}
                <td>{{cell}}</td>
                {% endfor %}
                <td contenteditable="false">
                    <script>
                        document.writeln('<button id="' + String({{row}})+'_button"');
                    </script>
                    type="button" onclick="makeEditable({{row}})">Edit Connector</button>
                </td>
            </tr>           
        {% endfor %}
    </table>        
</body>

1 个答案:

答案 0 :(得分:1)

连接时,请在值周围使用单引号:

button.setAttribute("onclick", "makeUneditable('" + row_id + "')")