网页不会呈现我的Javascript功能

时间:2016-01-30 20:14:08

标签: javascript html

我将文本文件保存为index.html并使用它来测试此功能,但是当我点击按钮时没有任何反应。

<!DOCTYPE html>
<html>
    <body>
        <button onclick="testamber()">Click here</button>

        <script>
            var testamber = function() {
                var ambersands = ["&", "&&", "&&&", "&&", "&",]
                var text = "";
                var i;
                for (i = 0; i < ambersands.length; i++) {
                    text += ambersands[i] + "<br>";
                }
            };
        </script>
    </body>
</html>

2 个答案:

答案 0 :(得分:0)

  

我需要像浏览器一样向浏览器呈现一个&符号模式。 &安培;&安培; &安培;&安培;&安培; &安培;&安培; &安培;

您可以使用document.write

替换浏览器html
<body>
    <button onclick="testamber()">Click here</button>

    <script>
        function testamber() {
            var ampersands = ["&amp;", "&amp;&amp;", "&amp;&amp;&amp;", "&amp;&amp;", "&amp;" ]
            var text = "";
            for (var i = 0; i < ampersands.length; i++) {
                text += ampersands[i] + "<br/>";
            }
            document.write(text);
        };
    </script>
</body>

或者你可以提供它去的地方,例如<div id='output'></div>并设置它,离开按钮,例如$("#output").text(text);。这使用了jquery,但你可以在标准的js中找到相同的东西。

答案 1 :(得分:-1)

您需要输出结果

<button onclick="testamber()">Click here</button>
<div id="output"></div>
for key_idx, key in enumerate(self.data.names):
    print type(self.data[key][0]) 
    if type(self.data[key][0]) == numpy.float32:
        table_cmd += "'%s' FLOAT" % key
    if type(self.data[key][0]) == numpy.float64:
        table_cmd += "'%s' DOUBLE" % key
    if type(self.data[key][0]) == numpy.int16:
        table_cmd += "'%s' INTEGER" % key 
    if type(self.data[key][0]) == numpy.int32:
        table_cmd += "'%s' INTEGER" % key 
    if type(self.data[key][0]) == numpy.string_:
        table_cmd += "'%s' TEXT" % key 
    if key_idx < self.shape[1]-1:
        table_cmd += ", "
table_cmd += ")"
print table_cmd