반응형
jQuery는 div 태그 안에 이미지를 추가합니다.
div 태그가 있습니다
<div id="theDiv">Where is the image?</div>
div 안에 이미지 태그를 추가하고 싶습니다
최종 결과 :
<div id="theDiv"><img id="theImg" src="theImg.png" />Where is the image?</div>
다음을 시도 했습니까?
$('#theDiv').prepend('<img id="theImg" src="theImg.png" />')
내 2 센트 :
$('#theDiv').prepend($('<img>',{id:'theImg',src:'theImg.png'}))
$("#theDiv").append("<img id='theImg' src='theImg.png'/>");
여기 에서 설명서를 읽어야합니다 .
<div>
함수 image()
가 호출 될 때마다 태그 의 내용을 변경하려면 다음과 같이해야합니다.
자바 스크립트
function image() {
var img = document.createElement("IMG");
img.src = "/images/img1.gif";
$('#image').html(img);
}
HTML
<div id="image"></div>
<div><a href="javascript:image();">First Image</a></div>
Manjeet Kumar의 게시물 외에도 (그는 선언이 없었습니다)
var image = document.createElement("IMG");
image.alt = "Alt information for image";
image.setAttribute('class', 'photo');
image.src="/images/abc.jpg";
$(#TheDiv).html(image);
var img;
for (var i = 0; i < jQuery('.MulImage').length; i++) {
var imgsrc = jQuery('.MulImage')[i];
var CurrentImgSrc = imgsrc.src;
img = jQuery('<img class="dynamic" style="width:100%;">');
img.attr('src', CurrentImgSrc);
jQuery('.YourDivClass').append(img);
}
참고 URL : https://stackoverflow.com/questions/941206/jquery-add-image-inside-of-div-tag
반응형
'Programing' 카테고리의 다른 글
성공 및 오류 대신 새 jQuery AJAX 코드에 .done () 및 .fail ()을 사용해야합니까 (0) | 2020.06.13 |
---|---|
data.frame 2에 존재하지 않는 data.frame 1의 행을 찾으려면 두 개의 data.frame을 비교하십시오. (0) | 2020.06.12 |
정적 라이브러리의 Objective-C 범주 (0) | 2020.06.12 |
Ajax post ASP.NET MVC에 antiforgerytoken 포함 (0) | 2020.06.12 |
문자열에서 줄 바꿈 문자를 제거하는 방법은 무엇입니까? (0) | 2020.06.12 |