Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 jQuery失败,因为switch语句附加了额外的字符_Javascript_Jquery - Fatal编程技术网

Javascript jQuery失败,因为switch语句附加了额外的字符

Javascript jQuery失败,因为switch语句附加了额外的字符,javascript,jquery,Javascript,Jquery,我的html页面中有以下代码: $("#rulecondition").change(function () { var txt = $(this).val(); alert(txt); switch (txt) { case 'Always use this rule': $('#callerid_condition_container').hide(); $('#time_condition_c

我的html页面中有以下代码:

$("#rulecondition").change(function () {
    var txt = $(this).val();
    alert(txt);
    switch (txt)
    {
        case 'Always use this rule': 
            $('#callerid_condition_container').hide();
            $('#time_condition_container').hide();
            break;
        case 'Depends on who is calling':
            $('#callerid_condition_container').fadein();
            $('#time_condition_container').hide();
            break;
        case 'Depends on the time of day': 
            $('#time_condition_container').fadein();
            break;
        default:
    }
});​
当我加载页面时,我得到一个脚本错误,上面说:

SCRIPT5009: '​' is undefined 
testpage, line 262 character 6
下面是呈现的代码的外观:

$("#rulecondition").change(function () {
    var txt = $(this).val();
    alert(txt);
    switch (txt)
    {
        case 'Always use this rule': 
            $('#callerid_condition_container').hide();
            $('#time_condition_container').hide();
            break;
        case 'Depends on who is calling':
            $('#callerid_condition_container').fadein();
            $('#time_condition_container').hide();
            break;
        case 'Depends on the time of day': 
            $('#time_condition_container').fadein();
            break;
        default:
    }
});â
如您所见,我的jQuery方法的右括号后面有一些时髦的字符。 我不知道这是怎么产生的,也不知道如何摆脱它!
我的另一个问题是,为什么警报语句只显示每个选项中的第一个单词?因此,例如,如果用户选择“始终使用此规则”,警报将显示“始终”

你能给出规则条件的内容吗

你的时髦角色首先想到的是ms角色。你复制并粘贴了什么吗?-试着从头重写它。

你有两个问题

  • 怪人:
  • 在记事本++之类的编辑器中打开文件,将其设置为显示“所有字符”(空格和全部),然后删除右括号后的“不可见”字符

    此外,请检查您是否在UTF-8中,并将其放入没有BOM的UTF-8中。(编辑:使用“转换”而不是“编码”)

  • 仅使用“始终”值

  • 按照规定,选项的value属性不能是任何内容。我想您不应该在其中使用空格。

    这难道不是一个BOM(字节顺序标记)问题吗?!在记事本中复制所需代码(不包括红色字符)。从html中删除代码并粘贴复制到记事本中的代码。好吧,我建议使用记事本++,将文件转换为不带BOM的UTF8,然后保存。这应该是一个注释,而不是答案。谢谢。成功了。一定是复制粘贴中的一些古怪角色。。。这就是我为switch语句获取骨架所做的。谢谢。到你发帖的时候,我已经重写并修复了。但下一次,我会用记事本找到那个讨厌的角色。