我如何控制来自另一个HTML的元素?

时间:2014-08-20 04:21:52

标签: javascript html css image button

我在buttons.html中有按钮的标签,在images.html中有图片。 当我从buttons.html打开按钮时,我想从images.html隐藏1张图片。 我怎么能这样做? 这是buttons.html的按钮

<div class="onoffswitch">
  <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
  <label class="onoffswitch-label" for="myonoffswitch"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span> </label>
  <img src="image.jpg" /> 
</div>

CSS:

#myonoffswitch ~ img
{
    display:none;
}
#myonoffswitch:checked ~ img
{
    display:block;
}

1 个答案:

答案 0 :(得分:-2)

更改

    #myonoffswitch ~ img
    {
     display:none;
    }
    #myonoffswitch:checked ~ img
    {
     display:block;
}

.myonoffswitch ~ img
    {
     display:none;
    }
    .myonoffswitch:checked ~ img
    {
     display:block;
}

从我那里开始。