首先感谢yixianggao对我的帮助 你让我看的那几个文档对我的帮助真的很大 言归正传 依旧是这一段代码 现在我想将Popup窗体设置一个格式 页面大概内容就是上边有一条按钮 电影 电视剧什么的 下边是分为两个部分 左边是当点击上边那些按钮时所显示出来的内容 也就是那个DIV层 右边是当点击左边DIV层里的按钮时所显示出来的电影数据 遇到问题如下:如果在pbody.innerHTML中直接加入table会导致无法将下边的元素准确添加到每一个td中 还有一个问题 那个DIV的ID是txtHint 可为何使用txtHint.style行不通?还有一个技术上的问题 前边说了 我现在那个DIV层里的东西要变成按钮 这些按钮同样要加入键盘事件 问题出来了 用鼠标点击的话不会有任何问题 可是如果页面刚刚加载出来的话我直接按键盘上对应的键时会怎么样呢?设想解决方法应该是在点击上边按钮后所弹出来的DIV里的内容 也就是那些按钮 应该先设置成禁用 然后判断当禁用时键盘事件无效 不知可行否?小弟对JS才疏学浅 也就只能麻烦yixianggao大哥了
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><script type="text/javascript">var oPopup = window.createPopup();function InitializePopup() {
var pbody = oPopup.document.body;
pbody.style.border = "solid black 1px";
pbody.innerHTML = ""; var btna = oPopup.document.createElement("button");
btna.innerHTML = "电影(a)";
oPopup.document.body.appendChild(btna); btna.onclick = function() {
txtHint.innerHTML = "<table><tr><td>恐怖片</td><td>爱情片</td></tr></table>";
}; var btnb = oPopup.document.createElement("button");
btnb.innerHTML = "电视剧(b)";
oPopup.document.body.appendChild(btnb); btnb.onclick = function() {
txtHint.innerHTML = "<table><tr><td>内地电视剧</td><td>港台电视剧</td></tr></table>";
}; var txtHint = oPopup.document.createElement("div");
txtHint.id = "txtHint";
oPopup.document.body.appendChild(txtHint);
}function ShowPopup()
{
oPopup.show(100,0,800,600,document.body)
}function key_short(){
if (event == null)
{
alert("event is null: true.");
}
else
{
//alert(window.event.keyCode);
var key = window.event.keyCode;
if(key==65) a();
if(key==66) b();
}
}function a(){
oPopup.document.getElementById("txtHint").innerHTML="<table><tr><td>恐怖片</td><td>爱情片</td></tr></table>"
}
function b(){
oPopup.document.getElementById("txtHint").innerHTML="<table><tr><td>内地电视剧</td><td>港台电视剧</td></tr></table>"
}InitializePopup();</script>
</head><body>
<button onclick="ShowPopup()">Create pop-up!</button>
</body>
<script type="text/javascript">
<!--
document.body.onkeydown = function() {
if (oPopup.isOpen)
{
// Debug:
// 打开 alert 时,ShowPopup 须同时打开! //alert(event.keyCode);
key_short();
//ShowPopup();
}
};
//-->
</script>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><script type="text/javascript">var oPopup = window.createPopup();function InitializePopup() {
var pbody = oPopup.document.body;
pbody.style.border = "solid black 1px";
pbody.innerHTML = ""; var btna = oPopup.document.createElement("button");
btna.innerHTML = "电影(a)";
oPopup.document.body.appendChild(btna); btna.onclick = function() {
txtHint.innerHTML = "<table><tr><td>恐怖片</td><td>爱情片</td></tr></table>";
}; var btnb = oPopup.document.createElement("button");
btnb.innerHTML = "电视剧(b)";
oPopup.document.body.appendChild(btnb); btnb.onclick = function() {
txtHint.innerHTML = "<table><tr><td>内地电视剧</td><td>港台电视剧</td></tr></table>";
}; var txtHint = oPopup.document.createElement("div");
txtHint.id = "txtHint";
oPopup.document.body.appendChild(txtHint);
}function ShowPopup()
{
oPopup.show(100,0,800,600,document.body)
}function key_short(){
if (event == null)
{
alert("event is null: true.");
}
else
{
//alert(window.event.keyCode);
var key = window.event.keyCode;
if(key==65) a();
if(key==66) b();
}
}function a(){
oPopup.document.getElementById("txtHint").innerHTML="<table><tr><td>恐怖片</td><td>爱情片</td></tr></table>"
}
function b(){
oPopup.document.getElementById("txtHint").innerHTML="<table><tr><td>内地电视剧</td><td>港台电视剧</td></tr></table>"
}InitializePopup();</script>
</head><body>
<button onclick="ShowPopup()">Create pop-up!</button>
</body>
<script type="text/javascript">
<!--
document.body.onkeydown = function() {
if (oPopup.isOpen)
{
// Debug:
// 打开 alert 时,ShowPopup 须同时打开! //alert(event.keyCode);
key_short();
//ShowPopup();
}
};
//-->
</script>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><script type="text/javascript">var oPopup = window.createPopup();function InitializePopup() {
var pBody = oPopup.document.body;
pBody.style.border = "solid black 1px";
pBody.innerHTML = ""; var btna = oPopup.document.createElement("button");
btna.innerHTML = "电影(a)";
pBody.appendChild(btna); var btnb = oPopup.document.createElement("button");
btnb.innerHTML = "电视剧(b)";
pBody.appendChild(btnb); var leftDiv = oPopup.document.createElement("div");
leftDiv.id = "leftDiv";
leftDiv.style.styleFloat = "left";
leftDiv.style.border = "1px dashed red";
leftDiv.style.width = "399px";
leftDiv.style.height = "500px";
pBody.appendChild(leftDiv); var rightDiv = oPopup.document.createElement("div");
rightDiv.id = "rightDiv";
rightDiv.style.styleFloat = "right";
rightDiv.style.border = "1px solid blue";
rightDiv.style.width = "399px";
rightDiv.style.height = "500px";
pBody.appendChild(rightDiv); btna.onclick = function() {
a();
}; btnb.onclick = function() {
b();
};
}function ShowPopup()
{
oPopup.show(100,0,800,600,document.body)
}function key_short(){
if (event == null)
{
alert("event is null: true.");
}
else
{
//alert(window.event.keyCode);
var key = window.event.keyCode;
if(key==65) a();
if(key==66) b();
if(key==67) c();
if(key==68) d();
if(key==69) e();
if(key==70) f();
}
}function a(){
var leftDiv = oPopup.document.getElementById("leftDiv");
leftDiv.innerHTML = ""; var btnc = oPopup.document.createElement("button");
btnc.innerHTML = "恐怖片(c)";
btnc.onclick = c;
leftDiv.appendChild(btnc); var btnd = oPopup.document.createElement("button");
btnd.innerHTML = "爱情片(d)";
btnd.onclick = d;
leftDiv.appendChild(btnd);
}
function b(){
var leftDiv = oPopup.document.getElementById("leftDiv");
leftDiv.innerHTML = ""; var btne = oPopup.document.createElement("button");
btne.innerHTML = "内地电视剧(e)";
btne.onclick = e;
leftDiv.appendChild(btne); var btnf = oPopup.document.createElement("button");
btnf.innerHTML = "港台电视剧(f)";
btnf.onclick = f;
leftDiv.appendChild(btnf);
}
function c(){
oPopup.document.getElementById("rightDiv").innerHTML = "播放恐怖片 :(";
}
function d(){
oPopup.document.getElementById("rightDiv").innerHTML = "播放爱情片 :b...";
}
function e(){
oPopup.document.getElementById("rightDiv").innerHTML = "播放内地电视剧 ^_^";
}
function f(){
oPopup.document.getElementById("rightDiv").innerHTML = "播放港台电视剧 @_@";
}InitializePopup();</script>
</head><body>
<button onclick="ShowPopup()">Create pop-up!</button>
</body>
<script type="text/javascript">
<!--
document.body.onkeydown = function() {
if (oPopup.isOpen)
{
// Debug:
// 打开 alert 时,ShowPopup 须同时打开! //alert(event.keyCode);
key_short();
//ShowPopup();
}
};
//-->
</script>
</html>
转而检查其父对象 window 是否能触发 event,如果能响应则可解,否则无解!说到底,经验 + 冷静思考 -> 解题思路 + 实验 -> 问题得解!
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><script type="text/javascript">var oPopup = window.createPopup();var buttonMonitor = {};function SetButtonMonitor(keyName) {
buttonMonitor[keyName] = true;
}
function GetButtonMonitor(keyName) {
return buttonMonitor[keyName];
}
function ResetButtonMonitor() {
for (var p in buttonMonitor)
{
buttonMonitor[p] = false;
}
}function InitializePopup() {
var pBody = oPopup.document.body;
pBody.style.border = "solid black 1px";
pBody.innerHTML = ""; var btna = oPopup.document.createElement("button");
btna.innerHTML = "电影(a)";
pBody.appendChild(btna); var btnb = oPopup.document.createElement("button");
btnb.innerHTML = "电视剧(b)";
pBody.appendChild(btnb); var leftDiv = oPopup.document.createElement("div");
leftDiv.id = "leftDiv";
leftDiv.style.styleFloat = "left";
leftDiv.style.border = "1px dashed red";
leftDiv.style.width = "399px";
leftDiv.style.height = "500px";
pBody.appendChild(leftDiv); var rightDiv = oPopup.document.createElement("div");
rightDiv.id = "rightDiv";
rightDiv.style.styleFloat = "right";
rightDiv.style.border = "1px solid blue";
rightDiv.style.width = "399px";
rightDiv.style.height = "500px";
pBody.appendChild(rightDiv); btna.onclick = function() {
a();
}; btnb.onclick = function() {
b();
};
}function ShowPopup()
{
oPopup.show(100,0,800,600,document.body)
}function key_short(){
if (event == null)
{
alert("event is null: true.");
}
else
{
//alert(window.event.keyCode);
var key = window.event.keyCode;
if(key==65) a();
if(key==66) b();
if(key==67) c();
if(key==68) d();
if(key==69) e();
if(key==70) f();
}
}function a(){
var leftDiv = oPopup.document.getElementById("leftDiv");
leftDiv.innerHTML = ""; var btnc = oPopup.document.createElement("button");
btnc.innerHTML = "恐怖片(c)";
btnc.onclick = c;
leftDiv.appendChild(btnc); var btnd = oPopup.document.createElement("button");
btnd.innerHTML = "爱情片(d)";
btnd.onclick = d;
leftDiv.appendChild(btnd); ResetButtonMonitor();
SetButtonMonitor("c");
SetButtonMonitor("d");
}
function b(){
var leftDiv = oPopup.document.getElementById("leftDiv");
leftDiv.innerHTML = ""; var btne = oPopup.document.createElement("button");
btne.innerHTML = "内地电视剧(e)";
btne.onclick = e;
leftDiv.appendChild(btne); var btnf = oPopup.document.createElement("button");
btnf.innerHTML = "港台电视剧(f)";
btnf.onclick = f;
leftDiv.appendChild(btnf); ResetButtonMonitor();
SetButtonMonitor("e");
SetButtonMonitor("f");
}
function c(){
if (GetButtonMonitor("c"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放恐怖片 :(";
}
function d(){
if (GetButtonMonitor("d"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放爱情片 :b...";
}
function e(){
if (GetButtonMonitor("e"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放内地电视剧 ^_^";
}
function f(){
if (GetButtonMonitor("f"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放港台电视剧 @_@";
}InitializePopup();</script>
</head><body>
<button onclick="ShowPopup()">Create pop-up!</button>
</body>
<script type="text/javascript">
<!--
document.body.onkeydown = function() {
if (oPopup.isOpen)
{
// Debug:
// 打开 alert 时,ShowPopup 须同时打开! //alert(event.keyCode);
key_short();
//ShowPopup();
}
};
//-->
</script>
</html>
不过代码比较烂,凑合看看吧L@_@K
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><script type="text/javascript">var oPopup = window.createPopup();var buttonMonitor = {};
var highlightButton = null;
var topButtons = null;function SetHighlightButton(btn) {
BlackoutHighlightButton();
highlightButton = btn;
btn.style.backgroundColor = "yellow";
}
function BlackoutHighlightButton() {
if (highlightButton)
highlightButton.style.backgroundColor = "";
}
function HighlightPreviousButton() {
if (highlightButton
&& highlightButton.PreviousButton)
SetHighlightButton(highlightButton.PreviousButton);
}
function HighlightNextButton() {
if (highlightButton
&& highlightButton.NextButton)
SetHighlightButton(highlightButton.NextButton);
}
function HighlightFirstUpButton() {
if (highlightButton
&& highlightButton.FirstUpButton)
SetHighlightButton(highlightButton.FirstUpButton);
}
function HighlightFirstDownButton() {
if (highlightButton
&& highlightButton.FirstDownButton)
SetHighlightButton(highlightButton.FirstDownButton);
}function SetButtonMonitor(keyName) {
buttonMonitor[keyName] = true;
}
function GetButtonMonitor(keyName) {
return buttonMonitor[keyName];
}
function ResetButtonMonitor() {
for (var p in buttonMonitor)
{
buttonMonitor[p] = false;
}
}function InitializePopup() {
var pBody = oPopup.document.body;
pBody.style.border = "solid black 1px";
pBody.innerHTML = ""; var btna = oPopup.document.createElement("button");
btna.innerHTML = "电影(a)";
pBody.appendChild(btna); var btnb = oPopup.document.createElement("button");
btnb.innerHTML = "电视剧(b)";
pBody.appendChild(btnb); var leftDiv = oPopup.document.createElement("div");
leftDiv.id = "leftDiv";
leftDiv.style.styleFloat = "left";
leftDiv.style.border = "1px dashed red";
leftDiv.style.width = "399px";
leftDiv.style.height = "500px";
pBody.appendChild(leftDiv); var rightDiv = oPopup.document.createElement("div");
rightDiv.id = "rightDiv";
rightDiv.style.styleFloat = "right";
rightDiv.style.border = "1px solid blue";
rightDiv.style.width = "399px";
rightDiv.style.height = "500px";
pBody.appendChild(rightDiv); btna.onclick = function() {
a();
}; btnb.onclick = function() {
b();
}; SetHighlightButton(btna);
btna.NextButton = btnb;
btnb.PreviousButton = btna; topButtons = [btna, btnb];
//alert(topButtons.length);
}function ShowPopup()
{
oPopup.show(100,0,800,600,document.body)
}function key_short(){
if (event == null)
{
alert("event is null: true.");
}
else
{
//alert(window.event.keyCode);
var key = window.event.keyCode;
if(key==65) a();
if(key==66) b();
if(key==67) c();
if(key==68) d();
if(key==69) e();
if(key==70) f(); // Left arrow
if(key==37) HighlightPreviousButton();
// Right arrow
if(key==39) HighlightNextButton();
// Up arrow
if(key==38) HighlightFirstUpButton();
// Down arrow
if(key==40) HighlightFirstDownButton();
// Enter
if (key==13 && highlightButton)
highlightButton.click();
}
}function a(){
var leftDiv = oPopup.document.getElementById("leftDiv");
leftDiv.innerHTML = ""; var btnc = oPopup.document.createElement("button");
btnc.innerHTML = "恐怖片(c)";
btnc.onclick = c;
leftDiv.appendChild(btnc); var btnd = oPopup.document.createElement("button");
btnd.innerHTML = "爱情片(d)";
btnd.onclick = d;
leftDiv.appendChild(btnd); ResetButtonMonitor();
SetButtonMonitor("c");
SetButtonMonitor("d"); SetHighlightButton(btnc);
btnc.NextButton = btnd;
btnd.PreviousButton = btnc; btnc.FirstUpButton = topButtons[0];
btnd.FirstUpButton = topButtons[0]; topButtons[0].FirstDownButton = btnc;
topButtons[1].FirstDownButton = btnc;
}
function b(){
var leftDiv = oPopup.document.getElementById("leftDiv");
leftDiv.innerHTML = ""; var btne = oPopup.document.createElement("button");
btne.innerHTML = "内地电视剧(e)";
btne.onclick = e;
leftDiv.appendChild(btne); var btnf = oPopup.document.createElement("button");
btnf.innerHTML = "港台电视剧(f)";
btnf.onclick = f;
leftDiv.appendChild(btnf); ResetButtonMonitor();
SetButtonMonitor("e");
SetButtonMonitor("f"); SetHighlightButton(btne);
btne.NextButton = btnf;
btnf.PreviousButton = btne; btne.FirstUpButton = topButtons[0];
btnf.FirstUpButton = topButtons[0]; topButtons[0].FirstDownButton = btne;
topButtons[1].FirstDownButton = btne;
}
function c(){
if (GetButtonMonitor("c"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放恐怖片 :(";
}
function d(){
if (GetButtonMonitor("d"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放爱情片 :b...";
}
function e(){
if (GetButtonMonitor("e"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放内地电视剧 ^_^";
}
function f(){
if (GetButtonMonitor("f"))
oPopup.document.getElementById("rightDiv").innerHTML = "播放港台电视剧 @_@";
}InitializePopup();</script>
</head><body>
<button onclick="ShowPopup()">Create pop-up!</button>
</body>
<script type="text/javascript">
<!--
document.body.onkeydown = function() {
if (oPopup.isOpen)
{
// Debug:
// 打开 alert 时,ShowPopup 须同时打开! //alert(event.keyCode);
key_short();
//ShowPopup();
}
};
//-->
</script>
</html>
{
oPopup.show(0,0, document.body.offsetWidth, document.body.offsetHeight,document.body)
}
function ShowPopup()
{
oPopup.show(0,-50, document.body.offsetWidth, document.body.offsetHeight,document.body)
}