javascript - 如何防止 HTML 中的 <script> 标记(JavaScript)前后换行?

标签 javascript html css

我目前正在开发一个用 HTML(当然还有 CSS)编写的网站 我有一个 JavaScript ......只是一个小幻灯片。

在脚本之前有一个带有图像的 anchor 标记 在脚本之后还有一个带有图像的 anchor 标记。

...
<a href="... .html">
    <img class="img" src="... .png" title="..."></a>
<script type="text/javascript">
    <!-- the script text -->
</script>
&nbsp;&nbsp;&nbsp;
<a href="... .html">
    <img class="img" src="... .png" title="..."></a>
...

我的问题是脚本标签前后的换行符。我想要它是

image    slideshow(script)    image

所有使用的图像(包括幻灯片内容)具有相同的高度。

我试过 display: inline;white-space: nowrap; (以及所有其他空白的东西) 我已经将它直接放入 html 文件中(style="display:inline;"style="white-space:nowrap;" 并放入css 文件(script { display: inline; }script { white-space: nowrap; })

有人知道如何防止脚本标签前后换行吗??

最佳答案

我建议将这些元素中的每一个都放在一个单独的 div 中,给它们一个固定的宽度,然后相应地 float 它们(如果你这样做,一定要清除你的 float )。

<div id="leftImg" style="width:220px; float:left;">
<img src="..." />
</div>

<div id="slideShow" style="width:220px; float:left;">
<script>your script here</script>
</div>

<div id="rightImg" style="width:220px; float:left;">
<img src="..." />
</div>

<div style="clear:left;"></div>

编辑:页面正文中的幻灯片脚本没有任何问题。如果它是发布信息的脚本,则出于安全目的必须进行服务器端验证,但您的操作方式没有任何问题。

关于javascript - 如何防止 HTML 中的 &lt;script&gt; 标记(JavaScript)前后换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13730459/

相关文章:

javascript - 如何向上滑动当前div

html - 使整个 div 在悬停时发生变化

css - 汉堡菜单 : Animation in CSS (Rotate and Transform of "two" lines)

javascript - onclick 函数使用 classList 添加和删除 CSS 类

javascript - jQuery 和动态库

html - z-index 不适用于图像和 p 标签

jquery - 当内容滚动到 View 中时激活 CSS3 动画

html - 如何声明输入框的内半径

javascript - 为什么 Chrome 和 FireFox 控制台打印 'undefined' ?

javascript - 匹配2个单词的正则表达式