2

html 页面包含 3 个单选按钮 - 红色、绿色、蓝色。如果我们选择了单选按钮中的任何一个,则必须打开新窗口,并且该窗口背景颜色应该是选定的单选按钮颜色。谁能帮我解决这个问题..

4

3 回答 3

1

试试这个(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);
}
于 2012-07-04T11:45:56.680 回答
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')" />
于 2012-07-04T11:51:04.130 回答
-1
var newwindow = window.open('popup.aspx','Color Popup','height=400,width=200');
newwindow.document.body.style.background = "#000";
于 2012-07-04T11:49:21.467 回答