$(focus_On).focus();
其中focus_on = #start_Time_Mo
未将焦点设置为该输入字段。
$(focus_On).css("color","red");
的位置将该字段中的文字设置为红色。
为什么.focus()
现在有效?
示例代码:
$last_Time = $(event.target);
已设置为单击#start_Time_XX
是动态创建的on
。检查有效时间范围后,如果时间超出范围突出显示,字体颜色为红色,并将焦点设置回该输入字段。
$("#detail_Section").on("blur", "#start_Time_Mo, #start_Time_Tu, #start_Time_Wed, #start_Time_Th, #start_Time_Fr, #start_Time_Sa, #start_Time_Su", function(event) {
earliest = (period_Definitions["morning_Start"]).split(":");
earliest_Time = new Date(1970, 1, 1, earliest["0"], earliest["1"], 0, 0);
latest = (period_Definitions["evening_End"]).split(":");
latest_Time = new Date(1970, 1, 1, latest["0"], latest["1"], 0, 0);
test_Times = ($last_Time.val()).split(":");
test_Time = new Date(1970, 1, 1, test_Times["0"], test_Times["1"], 0, 0);
if (test_Time >= earliest_Time && test_Time <= latest_Time) {
console.log("time good");
} else {
focus_On = "#" + $last_Time.attr("id");
$(focus_On).css("color", "red");
$(focus_On).focus();
}
last_String = "";
});
恼人地说,这适用于js小提琴:fiddle
答案 0 :(得分:0)
尝试
$("#[id^="+ $last_Time.attr("id")+"]").focus(function()
{
css("color","red")
});