appedn可以同時(shí)插入圖片和文字嗎
var?$content?=?$("#dc").val();//變量1?文本 var?$jieshou?=?$("#main");//被插入的地方 $jieshou.append("<img?src='icon/1.png'>"?,?"<p>"+":"+$content+"</p>");//表達(dá)式
問題來了,單獨(dú)插入圖片或者文本都可以實(shí)現(xiàn),但是兩者相加后就只能輸入文字,不能同時(shí)輸出文本加圖片。有大佬解釋一下為什么嗎?
還是不能用append方法,
完整代碼
<!DOCTYPE?html> <html> <head> ????<meta?charset="UTF-8"> ????<title>Title</title> ????<link?rel="stylesheet"?href="css/danmu.css"> ????<script?src="js/jquery-1.9.1.min.js"></script> ????<script?src="js/animate.min.js"></script> </head> <body> <script> ????$(document).ready(function?()?{ ????????$("#send1").click(function?()?{ ????????????var?pageH=parseInt($("#main").height()); ????????????var?$content?=?$("#dc").val(); ????????????var?$jieshou?=?$("#main"); ???????????//?var?$img?=?$("#img2").html("<img?src='icon/2.png'>"); ???????????//?$img.css({"width":"30px","height":"30px",}); ????????????var?_top=parseInt(Math.random()*pageH); ????????????$jieshou.append("<img?src='icon/1.png'>"?,?"<p>"+":"+$content+"</p>"); ????????????$("p:last-child").css({"top":_top,"color":"white",}); ????????????$("p:last-child").animate({"left":"-200px"},8000); ????????????$("img:last-child").css({"width":"30px","height":"30px","top":_top}); ????????????$("img:last-child").animate({"left":"-200px"},8000); ????????}) ???????? ????}) </script> <div?id="content"> ????<div?id="main"> ????????<p></p> ????</div> ????<div?id="send">???????? ????????<div?id="co"> ????????????<button?id="open">開啟彈幕</button> ????????????<button?id="close">關(guān)閉彈幕</button> ????????</div> ????????<div?id="danmu"> ????????????<input?type="text"?placeholder="發(fā)個(gè)友好的彈幕"?id="dc"> ????????</div> ????????<div?id="finish"> ????????????<button?id="send1">發(fā)送</button> ????????</div> ????</div> ???? </div> </body> </html>
實(shí)現(xiàn)一個(gè)彈幕圖片+文字的效果
2019-08-30
可以?