简体   繁体   English

如何使用innerHTML更改图像大小来为其提供一个id Javascript?

[英]How to give this an id Javascript using innerHTML changing image size?

I am trying to find a easy way of making a pop-up box that uses the image al-ready in a link using function (this);. 我试图找到一种简单的方法来制作一个弹出框,该弹出框使用功能(this);在链接中使用图像。 however I would like to change the size of the image in the pop up box however I am having problems targeting it. 但是,我想在弹出框中更改图像的大小,但是在定位时遇到了问题。 I tried to give it an id but that does not work. 我尝试给它提供一个ID,但这不起作用。

   function fullScreenpopup(x){
    var b = x.innerHTML;
    var divpopup = document.createElement("div");
    divpopup.innerHTML = b + '<a href = "javascript:void(0)" 
    onclick ="fullScreengetrid()">Close</a>';
    b.id = "imagepopup"; // this line does not work
    divpopup.setAttribute('class', 'white_content_philips');
    divpopup.setAttribute('id', 'popupbox');
    document.body.appendChild(divpopup);
    var popupdiv = document.createElement("div");
    popupdiv.setAttribute('class', 'black_overlay_philips');
    popupdiv.setAttribute('id', 'fadepopup');
    document.body.appendChild(popupdiv);
   }

any ideas please? 有什么想法吗?

This is what the code relates to 这就是代码所涉及的

<div style="float:left;">
<a href = "javascript:void(0)" onclick ="fullScreenpopup(this)"><img 
src="acb.jpg" 
alt="abc" width="300" height="225" 
class="alignnone size-medium wp-image-1807" /></a>
</div>

I assume id is getting assigned correctly in the DOM and you can verify this through the debugger. 我假设在DOM中正确分配了id ,您可以通过调试器进行验证。 I think your biggest issue is assigning width and height to the image in HTML. 我认为您最大的问题是为HTML中的图像分配widthheight This will override any changes you make in CSS. 这将覆盖您在CSS中所做的任何更改。 Try. 尝试。

<img src="acb.jpg"
     alt="abc"
     class="alignnone size-medium wp-image-1807" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM