我必须单击两次按钮才能使我的javascript和jquery工作

时间:2015-11-09 04:39:14

标签: javascript jquery

我必须单击一个按钮两次以使其工作,并且在我的switch语句中的任何情况下我的警报消息再增加一条警报消息。为什么会这样?

function parametros() {
    //var nombre = document.parametro.btncolor.value;
    //alert(nombre);

    contexto.beginPath();
    color = document.getElementById("color").value;
    ancho = document.getElementById("ancho").value;

    function check() 
    {
        if(document.getElementById("tipoextremo1").checked) 
        {
            tipoextremo = document.getElementById("tipoextremo1").value;
        }
        if(document.getElementById("tipoextremo2").checked) 
        {
            tipoextremo = document.getElementById("tipoextremo2").value;
        }
        if(document.getElementById("tipoextremo3").checked) 
        {
            tipoextremo = document.getElementById("tipoextremo3").value;
        }
    }

    check();
    alert(tipoextremo);

    $("button[type='button']").click(function()
    {
        switch(this.name){
        case 'btnarco':
            fun_arco(color, ancho, tipoextremo);
            alert("hi");
            break;
        case 'btncuad':
            fun_cuad(color, ancho, tipoextremo);
            break;
        case 'btnbezier':
            fun_bezier(color, ancho, tipoextremo);
            break;
        case 'btnzigzag':
            fun_zigzag(color, ancho, tipoextremo);
            break;
        case 'btnespiral':
            fun_espiral(color, ancho, tipoextremo);
            break;
        default:
            alert("hi");
        break;
        }
    });
        alert(tipoextremo);
}

function funcion01(){
    canvas = document.getElementById("lienzo");
    contexto = canvas.getContext("2d");
    //alert("Se Obtuvo el Contexto");
    //set the line width to 10 pixels
    linea(50, 50, 200, 50, "blue", 5, "round");

}

function linea(x1, y1, x2, y2, color, ancho, tipoextremo){
    //x1, y1, x2, y2 coordenadas iniciales y finales
    //color: string ej: "Red"
    //ancho: dado en px ej 10px
    //tipoextremo: "round", "square", "butt"
    contexto.beginPath(); 
    contexto.lineWidth = ancho;
    //set the line color to blue
    contexto.strokeStyle = color;
    //establece la posicion inicial
    contexto.moveTo(x1, y1);
    //draw the line
    contexto.lineTo(x2, y2);
    contexto.lineCap = tipoextremo;
    //make the line visible with the stroke color
    contexto.stroke();
}

function fun_borrar()
{
    alert("Funcion Borrar ha Sido Llamada");
    contexto.clearRect(0, 0, canvas.width, canvas.height);
}

function fun_variaslineas()
{ 
    linea(50, 100, 100, 100, "red", 5, "round");
    linea(100, 100, 100, 150, "blue", 5, "square");
    linea(100, 150, 50, 150, "yellow", 5, "butt"); 
    linea(50, 150, 50, 100, "green", 5, "round");
}

这些行之间的更多代码用于上面的交换机语句以进入函数。

window.addEventListener("load", funcion01, false);

0 个答案:

没有答案
相关问题