![](/img/trans.png)
[英]How to insert an html element before another without shifting the originals position
[英]Insert image in HTML without shifting of text
我必須使用javascript在文字之間插入一個小圖像。 當我插入圖像時,文本隨圖像進入而右移。我想插入圖像,以使文本不會移動或移位,並且圖像會使用javascript疊加。 我當前的功能是
var paraId = android.selection.getParagraphID();
var range = window.getSelection().getRangeAt(0);
var selectionContents = range.extractContents();
var span = document.createElement("span");
span.appendChild(selectionContents);
span.setAttribute("class","uiWebviewHighlight");
span.style.backgroundColor = "blue";
span.style.color = "white";
var spanID = 'SP' + paraId;
span.setAttribute("id",spanID);
var image = document.createElement("img");
image.src = "http://www.google.com/intl/en_com/images/logo_plain.png";
image.height=5;
image.width=5;
image.align = "top";
image.style.position="relative";
span.appendChild(image);
range.insertNode(span);
<img src="test.png" style="float:right;">
你可以把float:left;
也有風格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.