在函数中附加包含图像的div [英] Appending a div containing an image in a function

查看:80
本文介绍了在函数中附加包含图像的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的每一行代码都包含了所有内容,我可能把它弄乱了,一个小时后我发现它仍然找不到错误,所以这就是为什么我向你求助.

Everything comes just to the following single line of code, which I probably mess up somewhere and after an hour with something of searching for error I still don't find it, so that's why I'm turning up to you.

$("red").append("<div class = "reddot" style = "top: '+ y + 'px; left: '+ x +'px;"><img src='red.png' height='10' width='10'></div>");

.append()时;没有参数的语法都很好.将您看到的内容放入后,我找不到一条消息参数列表后出现Uncaught SyntaxError:missing".如果您认为这个括号对我不起作用,请帮助我找到神秘的括号或修正我的语法,或者用其他方式写出来.对这个转储问题很抱歉,我为此进行了很多搜索,但是在append方法中实现两个或多个html标签并没有说什么. P.S.这个想法是通过在其他位置生成坐标来加载保存图像的容器.

When .append(); is without an argument everything with the syntax is good. After I put what you see in, pops up a message "Uncaught SyntaxError: missing ) after argument list" which I can't find. Please help me to find the mysterious bracket or to fix my syntax or to write this in another way if you think this one won't ever work for me. Sorry for this dump question, I searched a lot for this but it was nowhere said about implementing two or more html tags within an append method. P.S. The idea is to load a container holding an image by generated elsewhere coordinates.

推荐答案

$("red").append("<div class=\"reddot\" style=\"top: "+ y + "px; left: "+ x +"px;\"><img src='red.png' height='10' width='10'></div>");

在带有"的字符串中时,应将所有"转义,否则JS将假定字符串已结束

All the " should be escaped when in a string with " otherwise JS will assume the string has ended

这篇关于在函数中附加包含图像的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆