English 中文(简体)
如何从贾瓦特树立形象
原标题:How to set image position from Javascript
  • 时间:2017-02-02 11:12:53
  •  标签:
  • javascript

在以下法典中,我可以确定在贾瓦特使用的图像的位置。

document.getElementById("dis").disabled = true;
var counter = 0;
var x = document.getElementById("myDIV");
var y = document.createElement("img");
var y1 = document.createElement("img");
var y2 = document.createElement("img");
var xy = document.createElement("img");

function myFunction() {
  document.getElementById("dis").disabled = false;
  counter++;
  if (counter % 2 == 0) {
    if (y && xy && x) {
      y.style.display =  none ;
      xy.style.display =  inline ;
      xy.setAttribute("src", "line.png");
      xy.setAttribute("width", "75");
      xy.setAttribute("height", "3");
      xy.setAttribute("style", "margin:a b c d");
      document.body.appendChild(xy);
    }
  } else {
    xy.style.display =  none ;
    y.setAttribute("src", "circle.png");
    y.setAttribute("width", "236");
    document.body.appendChild(y);
    y.style.display =  inline ;
  }
}
<button id="dis" onclick="myFunc()">Click me</button>
<img src="num1.png" style="position:absolute;top:80px;" onclick="myFunction()" />
<div id="myDIV">
</div>
<p id="demo"></p>

我尝试了以下立场守则,但并未适当开展工作。

y.setAttribute("style", "margin-left:100px;");  
y.setAttribute("style", "margin-top:-60px;");  
问题回答

您应利用<条码>式<> > 字面获取您的CSS风格财产,例如:

y.style.marginLeft =  100px ;
y.style.maringTop =  -60px ;

<代码>Element.setAttribute(>>>,可用作变更对电离层扰动成分或其价值的特性,例如可在<代码>image上改动<>src,但setAttribute不适用于电离层扰动特性。

y.setAttribute("src", "anUrl.png");

遵循你的意见:

您可以使用电离层电离层电离层电离层装置,电离层电离层电离层电离层电离层电离层装置将包含你希望使用的风格:

y.classList.add(阁下)

更多信息,请见





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签