Javascript jQuery失败,因为switch语句附加了额外的字符
我的html页面中有以下代码: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
$("#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角色。你复制并粘贴了什么吗?-试着从头重写它。你有两个问题
按照规定,选项的value属性不能是任何内容。我想您不应该在其中使用空格。这难道不是一个BOM(字节顺序标记)问题吗?!在记事本中复制所需代码(不包括红色字符)。从html中删除代码并粘贴复制到记事本中的代码。好吧,我建议使用记事本++,将文件转换为不带BOM的UTF8,然后保存。这应该是一个注释,而不是答案。谢谢。成功了。一定是复制粘贴中的一些古怪角色。。。这就是我为switch语句获取骨架所做的。谢谢。到你发帖的时候,我已经重写并修复了。但下一次,我会用记事本找到那个讨厌的角色。