html中的javascript间距
<SCRIPT LANGUAGE="JavaScript">
DynamicImage1(xx) DynamicImage2(yy) DynamicImage3(zz)
</SCRIPT>
这段 JS 代码位于我的 HTML 表单中。 (每个函数会根据输入参数显示不同的值。)
如何设置这些图像之间的间距? 我希望它们都在同一行(默认情况下是这样),但之间有间距。
我正在考虑将其放入表格中,但我不确定这是否是最好的方法
<SCRIPT LANGUAGE="JavaScript">
DynamicImage1(xx) DynamicImage2(yy) DynamicImage3(zz)
</SCRIPT>
This snippet of JS is in my HTML sheet.
(Each function will display a different value based on the input parameter.)
How do I set the spacing between these images? I would like them all on the same row (as they are by default) but with the spacing between.
I am thinking about to put it in a table, but I am not sure if that is the best way
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更简洁的方法是将它们分开:
然后使用 CSS 设计它们的样式; 使用
float:left
将它们排成一行,并添加padding:right
将它们隔开。我说这是干净的方法; 不太干净的方法是保留现有内容,但在每个图像之间添加
document.write(" ")
。The cleaner approach is going to be to separate them:
Then style them using CSS; use
float:left
to put them in a row and addpadding:right
to space them out.I said this was the clean way; the less-clean way is to keep what you have but add
document.write(" ")
in between each image.不要直接在页面上编写代码,而是创建具有唯一 id 的通用容器(例如
Instead of writing code directly on page, create common container (say, < div id="images_container" >< / div >) with unique id and write images HTML one by one into this container using innerHTML property.
啊。 不要在需要避免的地方使用内联脚本,并且在可以直接创建和插入 DOM 时不要使用innerHTML。 并使用CSS来处理positionin/spacin方面。 图像已经内联显示,因此将 div 单独包裹在它们周围只会使事情变得复杂。
我猜测,在不知道您的方法的作用的情况下,但这就是您应该大致执行的操作:
JS DOM方法参考
为什么innerHTML不好? 虽然确实可以更快,但并不总是如此,并且无论如何,它很接近,但速度并不是 JS 的真正问题。 然而,innerHTML:
Ugh. Don't use inline scripts where you avoid them, and don't use innerHTML when direct DOM creation and insertion is available. And use CSS to handle the positionin/spacin aspect. Images already display inline, so wrapping divs around them individually is just complicating things.
Without knowing what your method does, I'm guessing, but this is what you should be doing roughly:
JS DOM methods reference
Why is innerHTML bad? Whilst it's true it can be faster, it's not always true, and it's close anyway, but then speed isn't really the problem with JS. However innerHTML: