超链接图像未显示在Chrome扩展程序中

时间:2016-09-02 11:34:33

标签: javascript jquery html css google-chrome-extension

我创建了一个简单的chrome扩展,它有两个勾选框,点击它们时应显示超链接图像。 html文件独立工作,但当我将它添加到扩展时,图像不显示。任何人都知道什么是错的?

<!DOCTYPE html>
<html>
    <head>

        <script>
      function toggleVisibility(id) {
       var el = document.getElementById(id);

       if (el.style.visibility=="visible") {
              el.style.visibility="hidden";
            }
         else {
              el.style.visibility="visible";
            }
         }
        </script>

        <style type="text/css">
        body{
            margin:0px;
            padding:0px;
            font-family: Arial, Helvetica, Sans-serif;
            font-size: 13px;
        }   
        .popupContainerDiv{
            width:350px;
            min-height: 150px;

        }
        </style>

    </head>

    <body>

        <label for="chkyt">YouTube</label>
        <input type="checkbox" id="chkyt" onChange="toggleVisibility('imgyt');" /><br/>


        <label for="chkfb">Facebook</label>
        <input type="checkbox" id="chkfb"  onChange="toggleVisibility('imgfb');" />
        <hr />

        <a href="http://www.youtube.com" target="_blank"><img id="imgyt" src="ytlogo.png" alt="YouTube" height="100" width="150" style="visibility:hidden"></a>

        <a href="http://www.facebook.com" target="_blank"><img id="imgfb" src="fblogo.png" alt="Facebook" height="100" width="100" style="visibility:hidden"></a>


    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您无法在扩展程序中添加内联Javascript。你需要将javascript分成js文件