Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript忽略switch语句中的变量_Javascript_Jquery_Html - Fatal编程技术网

Javascript忽略switch语句中的变量

Javascript忽略switch语句中的变量,javascript,jquery,html,Javascript,Jquery,Html,我试图做一个case语句,但是我的第一个switch语句的变量只是转到我的默认语句,当我的变量中有一个边类型的字符串时,例如:round、square、butt。我用alerttipoextremo测试了它,它确实包含值round、square或butt 对于第二个switch语句,当我在html中单击一个按钮并在case中执行该函数时,我试图将我的按钮名放入switch语句中,但是当使用alerthi时,它甚至没有进入默认语句,这意味着它在我的javascript中被完全忽略 鲍通 博拉尔

我试图做一个case语句,但是我的第一个switch语句的变量只是转到我的默认语句,当我的变量中有一个边类型的字符串时,例如:round、square、butt。我用alerttipoextremo测试了它,它确实包含值round、square或butt

对于第二个switch语句,当我在html中单击一个按钮并在case中执行该函数时,我试图将我的按钮名放入switch语句中,但是当使用alerthi时,它甚至没有进入默认语句,这意味着它在我的javascript中被完全忽略

鲍通 博拉尔 线形变异 阿科 卡达拉蒂卡 贝齐尔 之字形 埃斯皮拉尔

这是我的javascript部分

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

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

alert(color);
alert(ancho);

var boton_te = document.forms[0];
var i;
for (i = 0; i < boton_te.length; i++) {
    if (boton_te[i].checked) {
        tipoextremo = tipoextremo + boton_te[i].value + " ";
    }
}

document.getElementById("tipoextremo").value = tipoextremo;
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;
    }
});
}

未捕获引用错误:$未定义。这告诉您,$是一个未定义的变量。你没有将jQuery加载到你的项目中吗?是的,我在html中定义了我的jQuery,这不再是问题,我会编辑,但是我的tipoextremo变量,当我再次点击一个按钮时,它变圆了,然后我再次点击变圆了,它进入了第一个开关,但是第二个开关一直被忽略。你想在这里实现什么?tipoextremo的基本值是多少?为什么要设置document.getElementByIdtipoextremo.value=tipoextremo?为什么要设置tipoextremo=tipoextremo?为什么使用输入[type=button]而不是按钮[type=button]?为什么要将按钮事件处理程序包装到一个只在单击同一按钮时调用的函数中?请考虑创建一个小提琴,在这里你可以演示你的错误在哪里。happening@choz好的,我通过切换输入[type=button]与按钮[type=button]和tipoextremo=tipoextremo来实现它,tipoextremo只是一个测试,因为我想看看值是否真的被传递到了那个变量中。我在画布上画画,最后一个问题是,当我点击圆形、方形和对接类型的角的单选按钮时,它会被忽略,只会使“获取圆形角”,每次单击时,我都会收到一条alertHi消息,我会发布代码中的更改。
function parametros() { 
//var nombre = document.parametro.btncolor.value;
//alert(nombre);

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

alert(color);
alert(ancho);

var boton_te = document.forms[0];
var i;
for (i = 0; i < boton_te.length; i++) {
    if (boton_te[i].checked) {
        tipoextremo = tipoextremo + boton_te[i].value + " ";
    }
}

document.getElementById("tipoextremo").value = tipoextremo;
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;
    }
});
}