【问题标题】:How do I get javascript to run on my index.html file in EC2如何让 JavaScript 在 EC2 中的 index.html 文件上运行
【发布时间】:2020-08-14 04:46:03
【问题描述】:

我已经启动了一个 EC2 实例。在用户数据中,我有以下脚本,但我的 javascript 无法运行。我只看到文字。我应该怎么办?我在本地运行它并在我的浏览器中按预期工作。

#!/bin/bash

# get admin privileges
sudo su

# install httpd (Linux 2 version)
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "<body>
    Text here
    <br>
    <p id="quote"></p>
    <script>
        var affirmArray = [
            "text here", 
            "text here", 
            "text here", 
            "text here"
        ];
        var rand = Math.floor(Math.random() * affirmArray.length);

        function showquote(){
            document.getElementById("quote").innerHTML = affirmArray[rand];
        }
        showquote();
    </script>
</body>" > /var/www/html/index.html

【问题讨论】:

    标签: amazon-web-services apache amazon-ec2


    【解决方案1】:

    您没有链接到服务器上的 javascript 库的路径或主机,您需要在引用 javascript 函数之前执行此操作。

    自行下载并托管它,或获取 javascript 库的缩小版本的链接。

    在运行当前获得的脚本之前添加类似的内容。

    <script>file path/ or http://linkToMinifiedVersion</script>  
    
    

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 2020-09-04
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 2017-07-14
      • 2019-04-20
      相关资源
      最近更新 更多