在html中,打开一个具有所选背景颜色的新窗口

时间:2012-07-04 11:43:34

标签: javascript html

html页面包含3个单选按钮 - 红色,绿色,蓝色。如果我们选择任何一个单选按钮,则必须打开onw新窗口,并且该窗口背景颜色应为所选的radion按钮颜色。任何人都可以帮我解决这个问题..

3 个答案:

答案 0 :(得分:1)

试试这个(demo on jsbin.com,你可能需要允许弹出窗口):

HTML:

<label for="red">Red</label>
<input type="radio" id="red" name="windowcolor" data-color="red" />
<label for="green">Green</label>
<input type="radio" id="green" name="windowcolor" data-color="green" />
<label for="blue">Blue</label>
<input type="radio" id="blue" name="windowcolor" data-color="blue" />

JavaScript的:

function openWindowWithColor() {
  var color = this.getAttribute("data-color");
  console.debug("Open new window with color: " + color);
  var myNewWindow = window.open();
  myNewWindow.document.body.style.background = color;
} 

var radios = document.getElementsByTagName("input");

for(var i = 0; i < radios.length; i++) {
  radios[i].addEventListener("change", openWindowWithColor);
}

答案 1 :(得分:0)

var newwindow = window.open('popup.aspx','Color Popup','height=400,width=200');
newwindow.document.body.style.background = "#000";

答案 2 :(得分:0)

<script>
    function open(var color){
        //window.open("new_page.html#"+color);
        var myNewWindow = window.open("url");
        myNewWindow.document.body.style.background = color;
    }
</script>

<input type="radio" onclick="open('red')" />
<input type="radio" onclick="open('green')" />
<input type="radio" onclick="open('blue')" />