You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script中HTML与CSS关联失败,页面无显示求助

问题:Google Apps Script开发库存应用时页面无内容展示,HTML与CSS关联失败

我正在用Google Apps Script开发带登录功能的库存小应用,现在遇到HTML和CSS关联的问题,浏览器打开时页面完全没内容。

文件结构:
文件结构

code.gs代码

function doGet(request) {
  return HtmlService.createTemplateFromFile('Index')
      .evaluate();
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
    }

Index.html代码

<!DOCTYPE html>    
<html>    
 <head>    
   <base target="_top">
     <?!= include('Stylesheet'); ?>
    </head>    
<body>    
    <h2>Login Page</h2><br>    
    <div class="login">    
    <form id="login" method="get" action="login.php">    
        <label><b>User Name     
        </b>    
        </label>    
        <input type="text" name="Uname" id="Uname" placeholder="Username">    
        <br><br>    
        <label><b>Password     
        </b>    
        </label>    
        <input type="Password" name="Pass" id="Pass" placeholder="Password">    
        <br><br>    
        <input type="button" name="log" id="log" value="Log In Here">        
        <br><br>    
        <input type="checkbox" id="check">    
        <span>Remember Me</span>    
        <br><br>    
        Forgot <a href="#">Password</a>    
    </form>     
</div>    
</body>    
</html>     

Stylesheet.css代码

<style>

body  
{  
    margin: 0;  
    padding: 0;  
    background-color:#6abadeba;  
    font-family: 'Arial';  
}  
.login{  
        width: 382px;  
        overflow: hidden;  
        margin: auto;  
        margin: 20 0 0 450px;  
        padding: 80px;  
        background: #23463f;  
        border-radius: 15px ;  
        
}  
h2{  
    text-align: center;  
    color: #277582;  
    padding: 20px;  
}  
label{  
    color: #08ffd1;  
    font-size: 17px;  
}  
#Uname{  
    width: 300px;  
    height: 30px;  
    border: none;  
    border-radius: 3px;  
    padding-left: 8px;  
}  
#Pass{  
    width: 300px;  
    height: 30px;  
    border: none;  
    border-radius: 3px;  
    padding-left: 8px;  
    
}  
#log{  
    width: 300px;  
    height: 30px;  
    border: none;  
    border-radius: 17px;  
    padding-left: 7px;  
    color: blue;  


}  
span{  
    color: white;  
    font-size: 17px;  
}  
a{  
    float: right;  
    background-color: grey;  
}  
</style>

我已经参考Google官方文档修改过代码,但问题还是没解决,请问可能是什么原因?


问题原因及解决办法
  • CSS文件格式错误
    你的Stylesheet.css文件里包含了<style>标签,但Google Apps Script通过include函数引入CSS时,不需要额外的<style>标签。文件内容会直接插入到HTML的<head>中,嵌套的<style>标签会导致HTML解析异常,进而页面无法渲染。解决:删除Stylesheet.css里的<style>和</style>标签,只保留纯CSS代码。

  • 文件名匹配问题
    检查include('Stylesheet')里的文件名是否与实际文件完全一致,Google Apps Script的文件名区分大小写,若文件名拼写或大小写不匹配,会导致无法加载CSS内容。

  • 浏览器缓存干扰
    浏览器可能缓存了旧的页面资源,导致修改后无法实时生效。可以尝试用无痕模式打开页面,或按Ctrl+F5强制刷新。

  • CSS语法错误
    .login类中的margin: 20 0 0 450px;缺少单位,应改为margin: 20px 0 0 450px;。虽然这不会直接导致页面空白,但可能影响布局显示。

  • 脚本执行报错
    打开Google Apps Script编辑器的日志(菜单栏「查看」→「日志」),检查include函数是否执行出错,比如找不到指定文件的报错信息。


内容的提问来源于stack exchange,提问作者albetroz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 00:35:26