appedn可以同時插入圖片和文字嗎
var?$content?=?$("#dc").val();//變量1?文本
var?$jieshou?=?$("#main");//被插入的地方
$jieshou.append("<img?src='icon/1.png'>"?,?"<p>"+":"+$content+"</p>");//表達式問題來了,單獨插入圖片或者文本都可以實現,但是兩者相加后就只能輸入文字,不能同時輸出文本加圖片。有大佬解釋一下為什么嗎?
還是不能用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">關閉彈幕</button>
????????</div>
????????<div?id="danmu">
????????????<input?type="text"?placeholder="發個友好的彈幕"?id="dc">
????????</div>
????????<div?id="finish">
????????????<button?id="send1">發送</button>
????????</div>
????</div>
????
</div>
</body>
</html>實現一個彈幕圖片+文字的效果
2019-08-30
可以?
$jieshou.append("<img?src='icon/1.png'>"?,?"<p>"+":"+$content+"</p>");$jieshou.append("<img?src='icon/1.png'><p>"+":"+$content+"</p>"); 直接連著寫就行??親測可以