我對jQuery非常陌生,我在窗體上寫了一些驗證邏輯。在這個美妙社區的幫助下,我能夠了解如何發佈我的表格,並阻止回發。困惑是否返回false;是否需要
我使用button.click()事件來做到這一點,我知道什麼時候我需要保持表單發佈,我必須把return false;
,我明白爲什麼。例如:
var name = $("input#name").val();
if (name == "")
{
$("label#lblName").css('color','red');
$("input#name").focus();
return false;
}
我明白爲什麼在這種情況下返回false是很重要的。但在我的提交按鈕點擊事件的盡頭還有一個返回false,像這樣:
$(function()
{
$("#submitbutton").click(function()
{
//validate and submit form
return false; //WHY is this here? What purpose does it serve?
});
});
的原因,我問的是,我也寫一個函數來更改標籤顏色白回來的。模糊()。像這樣:
$(function()
{
$("input#name").blur(function()
{
var name = $("input#name").val();
if (name == '')
{
$("label#lblName").css('color','red');
}
else
{
$("label#lblName").css('color','');
}
//Do I need return false here? and why?
});
});
謝謝!