如何在子窗口中将文本写入div元素 [英] How to write text to div element in child window

查看:54
本文介绍了如何在子窗口中将文本写入div元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个简单的井字游戏,该游戏会打开一个子窗口,该子窗口是游戏的面板(包含按钮),但是,当我写入在子窗口中创建的div元素后,程序基本上停止将X和O写入到板上的按钮.

我用一个函数创建窗口:

I''m trying to write a simple tic tac toe game that opens a child window that is the board for the game (containing the buttons), however, after I write to a div element created in the child window, the program basically stops writing the Xs and Os to the buttons on the board.

I create the window with a function:

<pre lang="cs">function creatChildWindow()
         {
         childWindow = NewWin=window.open('','Window1',
              'toolbar=yes,status=yes,width=600,height=600,scrollbars=yes,resizable=yes,menubar=yes');
            childWindow.document.write( childWindowContent );
            childStatusDiv = childWindow.document.getElementById( "messageToPlayer" );
         }



然后尝试使用以下字符串写入div元素:



Then try to write to the div element using this string:

{
            if ( ticTacButtonName == "square1" && buttonPressedRecord[ 1 ] != "nothing" )
            {
            childStatusDiv.innerHTML = "Button 1 has already been pressed.";
            buttonAlreadyUsed = 1;
            }



此操作在前几次工作,然后停止工作(尝试向div元素写入状态消息.)

子窗口中的div元素定义为:



This works the first couple of times, then stops working (trying to write a status message to the div element.)

The div element in the child window is defined as:

</form>" + 
		                     "<div id="messageToPlayer">" +
                                "Start the game. X has the first turn.</div>


知道为什么它可能会停止写入div元素吗?

我是一个初学者,所以任何答案都可能会困扰我,但我想我也可以在这里尝试一下运气.

谢谢,

Mike


Any idea why it might stop writing to the div element?

I am a beginner, so any answers will probably be over my head, but figured I might as well try my luck here.

Thanks,

Mike

推荐答案

好像div标签在表单元素外部.您可以修复它并尝试吗?
Looks like div tag is outside form element. Could you fix it and try?


这篇关于如何在子窗口中将文本写入div元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆