javascript - jq中click(function)嵌套focus(function)不能用?
本文介绍了javascript - jq中click(function)嵌套focus(function)不能用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
$(function () {
$("#test_focus").focus(function () {
$("#test_focus").css("backgrand-color","#FFFFCC");
});
$("#btn").click(function () {
$("#test_focus").focus();
});
});
这样就能focus到input
但是我如果像下面这样写
$(function () {
$("#btn").click(function () {
$("#test_focus").focus(function () {
$("#test_focus").css("background-color","#FFFFCC");
})
});
});
就不能focus到input
是不是不能够在click(function)中再嵌套function?
新手~~ 望各位大大指导下~~
解决方案
$(function () {
$("#btn").click(function () {
$("#test_focus").focus(function () {
$("#test_focus").css("background-color","#FFFFCC");
})
//你这是给元素添加了一个事件,需要调用才能生效!
$("#test_focus").focus();
});
});
这篇关于javascript - jq中click(function)嵌套focus(function)不能用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文