Javascript Dreamweaver图像模式-脚本在HTML中工作,但不作为外部文件

Javascript Dreamweaver图像模式-脚本在HTML中工作,但不作为外部文件,javascript,html,css,modal-dialog,dreamweaver,Javascript,Html,Css,Modal Dialog,Dreamweaver,让我有点疯狂,这对你们所有的兽医来说应该很简单 简单地说,如果我只是删除并粘贴回Javascript文件位置行(有时必须这样做几次),那么代码在浏览器预览中工作,但不会在dreamweaver内部的实时视图中工作。如果保存所有文件并重新加载,代码将再次停止工作 如果所有代码都包含在HTML文件中,那么代码似乎可以正常工作,但是一旦我将脚本分离到外部文件中,所有代码都会崩溃。如有任何见解/帮助,将不胜感激。提前谢谢。代码如下: HTML: <!DOCTYPE html> <h

让我有点疯狂,这对你们所有的兽医来说应该很简单

简单地说,如果我只是删除并粘贴回Javascript文件位置行
(有时必须这样做几次),那么代码在浏览器预览中工作,但不会在dreamweaver内部的实时视图中工作。如果保存所有文件并重新加载,代码将再次停止工作

如果所有代码都包含在HTML文件中,那么代码似乎可以正常工作,但是一旦我将脚本分离到外部文件中,所有代码都会崩溃。如有任何见解/帮助,将不胜感激。提前谢谢。代码如下:

HTML:


<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="CSS/styles.css" rel="stylesheet" type="text/css">
    <script src="JS/scripts.js"></script>
</head>
<body>
    
<h2>Image Modal</h2>
<p>In this example, we use CSS to create a modal (dialog box) that is hidden by default.</p>
<p>We use JavaScript to trigger the modal and to display the current image inside the modal when it is clicked on. Also note that we use the value from the image's "alt" attribute as an image caption text inside the modal.</p>

<img src="images/thumbnail4.jpg" id="myImg" alt="Testes123" style="width:100%;max-width:300px">

<!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">&times;</span>
  <img class="modal-content" id="img01">
  <div id="caption"></div>
</div>


</body>
</html>


JAVASCRIPT:

// JavaScript Document
// Get the modal
var modal = document.getElementById("myModal");

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("myImg");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
  modal.style.display = "block";
  modalImg.src = this.src;
  captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
}


CSS:

body {font-family: Arial, Helvetica, sans-serif;}

#myImg {
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}

/* Caption of Modal Image */
#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

/* Add Animation */
.modal-content, #caption {  
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
  from {-webkit-transform:scale(0)} 
  to {-webkit-transform:scale(1)}
}

@keyframes zoom {
  from {transform:scale(0)} 
  to {transform:scale(1)}
}

/* The Close Button */
.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
}

.close:hover,
.close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content {
    width: 100%;
  }
}

HTML:
图像模态
在本例中,我们使用CSS创建默认隐藏的模式(对话框)

我们使用JavaScript触发模态,并在单击模态时显示模态内部的当前图像。还要注意,我们使用图像的“alt”属性中的值作为模式中的图像标题文本

&时代; 关闭模态的元素 var span=document.getElementsByClassName(“关闭”)[0]; //当用户单击(x)时,关闭模式对话框 span.onclick=function(){ modal.style.display=“无”; } CSS: 正文{字体系列:Arial,Helvetica,无衬线;} #myImg{ 边界半径:5px; 光标:指针; 过渡:0.3s; } #myImg:hover{opacity:0.7;} /*模态(背景)*/ .莫代尔{ 显示:无;/*默认情况下隐藏*/ 位置:固定;/*保持原位*/ z指数:1;/*位于顶部*/ 填充顶部:100px;/*框的位置*/ 左:0; 排名:0; 宽度:100%;/*全宽*/ 高度:100%;/*全高*/ 溢出:自动;/*根据需要启用滚动*/ 背景色:rgb(0,0,0);/*回退色*/ 背景色:rgba(0,0,0,0.9);/*黑色w/不透明度*/ } /*模态内容(图像)*/ .模态内容{ 保证金:自动; 显示:块; 宽度:80%; 最大宽度:700px; } /*模态图像字幕*/ #标题{ 保证金:自动; 显示:块; 宽度:80%; 最大宽度:700px; 文本对齐:居中; 颜色:#ccc; 填充:10px0; 高度:150像素; } /*添加动画*/ .模式内容#标题{ -webkit动画名称:缩放; -webkit动画持续时间:0.6s; 动画名称:缩放; 动画持续时间:0.6s; } @-webkit关键帧缩放{ 来自{-webkit变换:缩放(0)} 到{-webkit转换:缩放(1)} } @关键帧缩放{ 来自{transform:scale(0)} 到{变换:比例(1)} } /*关闭按钮*/ .结束{ 位置:绝对位置; 顶部:15px; 右:35px; 颜色:#f1f1; 字体大小:40px; 字体大小:粗体; 过渡:0.3s; } .关闭:悬停, .结束:聚焦{ 颜色:#bbb; 文字装饰:无; 光标:指针; } /*较小屏幕上的100%图像宽度*/ @仅介质屏幕和(最大宽度:700px){ .模态内容{ 宽度:100%; } }
好的,我想我自己解决了这个问题-如果脚本位置行位于文档的开头,那么它将失败,脚本位置行必须位于模态代码之后的正文末尾,这样它才能正常工作