js小技巧-引号多层嵌套-自提示上下键选择
html中的超链接中比如有多层嵌套,就会导致字符串被截取,出现很多问题
引号嵌套两层时,可以使用转义或者单双引号交替的形式实现,当引号嵌套达到三四层的时候,问题就出现了,该怎么办?
举个例子:”javascript:fnabc(‘abcd(“123″)’)”
html的href=以上的字符串
那么即使加了转义字符,以上的字符串还是会被截取为”javascript:fnabc(‘abcd(”
解决的方法是使用"代替引号
“javascript:fnabc(‘abcd(“123″)’)”
http://blog.csdn.net/panfang/article/details/7626032
监听回车、上、下键事件,实现自提示按上下键选择下拉项:
//监听回车、上、下键事件
$("#queryWord").keydown(function(e) {
var key = (e.keyCode) || (e.which) || (e.charCode);//兼容IE(e.keyCode)和Firefox(e.which)
var index = 0;
if (key == "38"){//向上
if($("#queryWord").val().length > 0){
$("#autocomplete").show();
$.each($("#autocomplete").children("li"),function(i,n){
// alert(i);
var $cr = $(n);
if($cr.children("a").hasClass("current")){
index = i - 1;
// alert(index);
$cr.children("a").removeClass("current");
}
});
// alert(index);
$("#autocomplete").children("li").eq(index).children("a").addClass("current");
}
}
if (key == "40"){//向下
if($("#queryWord").val().length > 0){
$("#autocomplete").show();
$.each($("#autocomplete").children("li"),function(i,n){
// alert(i);
var $cr = $(n);
if($cr.children("a").hasClass("current")){
index = 1 + i;
// alert(index);
$cr.children("a").removeClass("current");
}
});
// alert(index);
$("#autocomplete").children("li").eq(index).children("a").addClass("current");
}
}
if(key == "13"){
var enterIndex = 0;
if($("#queryWord").val().length > 0){
$("#autocomplete").show();
$.each($("#autocomplete").children("li"),function(i,n){
var $cr = $(n);
if($cr.children("a").hasClass("current")){
enterIndex = i;
$cr.children("a").removeClass("current");
}
});
$("#autocomplete").children("li").eq(enterIndex).children("a").addClass("current");
query($("#autocomplete").children("li").eq(enterIndex).children("a").children(".title").html());
}
}
});
