JavaScript过早停止

时间:2019-02-13 15:23:36

标签: javascript html canvas popup

在此先感谢您能提供的帮助。

我的任务是整理公司网站。我已经完成了大部分工作,但是却陷入了JavaScript的境地。

该网站有一个问卷调查表,其中包含三个类别的答案。根据分数,我绘制了一个三角形。我写了一个函数,它将返回我想要的计算。作为对此功能的测试,我可以将计算出的变量直接写到弹出窗口中。

我创建了另一个函数,然后在弹出窗口中使用CANVAS()绘制三角形。为了测试新功能是否正常工作,我在代码中尝试创建带有结果的弹出窗口。它可以创建弹出窗口,但不会写入弹出窗口,就像代码在创建弹出窗口之后停止一样。谁能告诉我我做错了什么?

问候 提请

代码:

    <script type="text/javascript">

            function myFunction() 
            {                   
                function calcD() 
                {
                var D1 = parseInt(document.forms.form1.elements.RadioGroup1.value);
                var D2 = parseInt(document.forms.form1.elements.RadioGroup4.value);
                var D3 = parseInt(document.forms.form1.elements.RadioGroup7.value);
                var D4 = parseInt(document.forms.form1.elements.RadioGroup10.value);
                var Ds  = D1 + D2 + D3 + D4;
                return Ds;
                }

                function calcI() 
                {
                var I1 = parseInt(document.forms.form1.elements.RadioGroup2.value);
                var I2 = parseInt(document.forms.form1.elements.RadioGroup5.value);
                var I3 = parseInt(document.forms.form1.elements.RadioGroup8.value);
                var I4 = parseInt(document.forms.form1.elements.RadioGroup11.value);
                var Is  = I1 + I2 + I3 + I4;
                return Is;
                }

                function calcB() 
                {
                var B1 = parseInt(document.forms.form1.elements.RadioGroup3.value);
                var B2 = parseInt(document.forms.form1.elements.RadioGroup6.value);
                var B3 = parseInt(document.forms.form1.elements.RadioGroup9.value);
                var B4 = parseInt(document.forms.form1.elements.RadioGroup12.value);
                var Bs  = B1 + B2 + B3 + B4;
                return Bs;
                }

                var X = 396.4;
                var Y = 250;
                var coS30 = 0.866025403784439;
                var siN30m = -0.5;
                var siN30p = 0.5;
                var Dx = X;
                var Dy = calcD() + Y;
                var Bx = X - (calcB()*coS30);
                var By = Y + (calcB()*siN30m);
                var Ix = X + (calcI()*coS30);
                var Iy = Y + (calcI()*siN30p);
                var Xs = (Dx + Bx + Ix)/3;
                var Ys = (Dy + By + Iy)/3;
            /*
                var myWindow1 = window.open("","MsgWindow","resizable,height=700,width=793");

                myWindow1.document.write('var X = ' + X);
                myWindow1.document.write('; var Y = ' + Y);
                myWindow1.document.write('; var coS30 = ' + coS30);
                myWindow1.document.write('; var siN30m = ' + siN30m);
                myWindow1.document.write('; var siN30p = ' + siN30p);
                myWindow1.document.write('; var Dx = ' + Dx);
                myWindow1.document.write('; var Dy = ' + Dy);
                myWindow1.document.write('; var Bx = ' + Bx);
                myWindow1.document.write('; var By = ' + By);
                myWindow1.document.write('; var Ix = ' + Ix);
                myWindow1.document.write('; var Iy = ' + Iy);
                myWindow1.document.write('; var Xs = ' + Xs);
                myWindow1.document.write('; var Ys = ' + Ys);
                myWindow1.document.close();
            */
        }

    </script>

    <script type="text/javascript">

                function draw() {

                    var myWindow1 = window.open("","MsgWindow","resizable,height=700,width=793");

                    myWindow1.document.write('var X = ' + X);
                    myWindow1.document.write('; var Y = ' + Y);
                    myWindow1.document.write('; var coS30 = ' + coS30);
                    myWindow1.document.write('; var siN30m = ' + siN30m);
                    myWindow1.document.write('; var siN30p = ' + siN30p);
                    myWindow1.document.write('; var Dx = ' + Dx);
                    myWindow1.document.write('; var Dy = ' + Dy);
                    myWindow1.document.write('; var Bx = ' + Bx);
                    myWindow1.document.write('; var By = ' + By);
                    myWindow1.document.write('; var Ix = ' + Ix);
                    myWindow1.document.write('; var Iy = ' + Iy);
                    myWindow1.document.write('; var Xs = ' + Xs);
                    myWindow1.document.write('; var Ys = ' + Ys);
                    myWindow1.document.close();


            /*  
                var ctx = myWindow1.document.getElementById('canvas').getContext('2d');
                var img = new Image();

                img.onload = function() {
                ctx.drawImage(img, 0, 0);
                ctx.beginPath();
                ctx.moveTo(Dx, Dy);
                ctx.lineTo(Bx, By);
                ctx.lineTo(Ix, Iy);
                ctx.fill();
                ctx.stroke();
                };
                img.src = "img/triangle.png";
            */
            };

    </script>

如果需要变量值:

var X = 396.4; 

var Y = 250;
var coS30 = 0.866025403784439;
var siN30m = -0.5;
var siN30p = 0.5;
var Dx = 396.4;
var Dy = 250;
var Bx = 396.4;
var By = 250;
var Ix = 396.4;
var Iy = 250;
var Xs = 396.3999999999999;
var Ys = 250;

0 个答案:

没有答案