点击图片后Javascript无法运行

时间:2019-05-06 10:47:30

标签: javascript html css

在此我想在单击图像时显示一个窗口。该图像是一个地址簿,应该在div id="janela2"中显示一个地址簿。我希望它可拖动并且可调整大小,但是最重要的是使其能够正常工作,因为我相信js代码是正确的,但是当我单击图像时,通讯录没有出现。

未运行的js代码是js的两个首要功能,我不知道为什么。我只放置了地址簿代码,以便您可以查看它是否仍然可以解决问题。到底是怎么回事?如何解决?

由于代码段不起作用,请检查codepen

第一部分已解决。现在,窗口显示了单击后的响应,但是现在地址簿不起作用。 https://codepen.io/Fropis/pen/mYydYd有新代码,但现在地址簿将无法使用。为什么?

https://codepen.io/Fropis/pen/XwJWjg

/**************************************** Contactos **********************************************************/
function openAB(){
    document.getElementById("janela2").innerHTML = document.getElementById("mydiv").innerHTML;
  }
  
  function fechar(){
    document.getElementById("janela2").innerHTML = "";
  }
 
 /*****************************THE ONE THAT MATTERS IS ABOVE****************/
  
   
html, body {
    width: 3779.527559055px;
   height: 100%;
   font-family: "Helvetica Neue", Helvetica, sans-serif;
   color: #444;
   -webkit-font-smoothing: antialiased;
   background-image: url("https://images4.alphacoders.com/111/111298.jpg");
   background-position: center;
   background-repeat: no-repeat;
   background-size: 350% 100%;
   font-family: Arial, Helvetica, sans-serif;
}

/* Place the navbar at the bottom of the page, and make it stick */
.navbar {
    background-color: none;
    left: 30%;
    position: absolute;
    bottom: 0;
    height: 500px;
    width: 1500px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 10%;
    padding-right: 10%;
    border-top-right-radius: 30px;
    border-top-left-radius: 30px;
    text-align: center;
    overflow: hidden;
  }

  #NetImg, #Home, #contact{
      width: 400px;
      height: 400px;
      padding:20px;
      background: none;
  }

  .panel {
    background: #fafafa;
    padding: 1em;
    width: 92.5%;
    margin: auto;
    max-width: 30em;
  }
  input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1em;
    margin-top: 0.5em;
    padding: 0.5em;
  }
  input:focus {
    outline: none;
  }
  input::after {
    width: 100%;
    height: 10px;
    background: red;
  }
  .nav-list {
    width: 92.5%;
    max-width: 30em;
    text-align: center;
    margin: auto;
  }
  .nav-list li {
    list-style: none;
    display: inline-block;
    background: white;
    padding: 0.7em;
    margin: 0 0.1em;
  }
  .nav-list .active {
    background-color: black;
  }

  #janela2{
    position: absolute;
    width:1900px;
    height:1500px;
    left:1500px;
    top:550px;
    border-radius:20px black solid;
  }
  
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="cale.css">
</head>
<body>
<div id="janela2">OLA</div>

<div id="mydiv" style="display:none;">
        <div id="navigation">
            <ul class="nav-list">
                <li id="js-show-all">Mostrar Todos</li>
                <li id="js-search">Procurar</li>
                <li id="js-add-new">Adicionar Contacto</li>
            </ul>
        </div>
        <div id="search-panel" class="panel">
            <h1>Procurar Contacto</h1>
            <form id="search" action="#">
                <div id="results"></div>
                <div>
                    <label>
                        <input type="text" name="search" id="search" placeholder="Insira nome do contacto" />
                    </label>
                </div>
                        <input type="submit" value="Procurar"/>
            </form>
        </div>
            <div id="contact-panel" class="panel">
                <form id="contact" action="#">
                    <h1>Adicionar Novo Contacto</h1>
                    <div>
                        <label>
                            <input type="text" name="person" id="name" placeholder="Jos&eacute Bigodes" required/>
                        </label>
                        <label>
                            <input type="text" name="phone" id="name" placeholder="912942923" maxlength="9" pattern=".{9,}"   required title="Insira 9 caracteres"/>
                        </label>
                        <label>
                            <input type="email" name="email" id="name" placeholder="nome@desk.com" pattern="+@desk.com" required/>
                        </label>
                    </div>
                    <div>
                        <input type="submit" value="Adicionar" />
                    </div>
                </form>
            </div>
        <div id = "show-panel" class="panel">
        </div>
    </div>
    <div class="navbar">
            <a><img onclick="openAb()" src="http://downloadicons.net/sites/default/files/address-book-icon-62889.png" id="contact"></a>
        </div>
</body>
<script src=cale.js></script>
</html>

2 个答案:

答案 0 :(得分:2)

openAb在html中有拼写错误,而在js中有openAB函数。替换为

 <img onclick="openAB()" .... 

答案 1 :(得分:0)

您的函数名称为openAB,但您正在调用openAb

<img onclick="openAB()" src="http://downloadicons.net/sites/default/files/address-book-icon-62889.png" id="contact">