我不能放在一起javascript if statment to activate my submit button if(username_ready && email_ready) ("#register").removeAttr("disabled");
所以我有兩個增值稅,如果他們都是真的我希望提交按鈕被激活。以上似乎不工作?我試圖把它拴住這個......刪除禁用,如果如果語句真的在JavaScript
$(document).ready(function()
{
$("#username").blur(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
//check the username exists or not from ajax
$.post("user_availability.php",{ username:$(this).val() } ,function(data)
{
if(data=='no') //if username not avaiable
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
var username_ready = false;
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
var username_ready = true;
});
}
});
});
});
</script>
<script src="jquery.js" type="text/javascript" language="javascript"></script>
<script language="javascript">
$(document).ready(function()
{
$("#email").blur(function()
{
//remove all the class add the messagebox classes and start fading
$("#box").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
//check the username exists or not from ajax
$.post("email_availability.php",{ email:$(this).val() } ,function(data)
{
if(data=='no') //if username not avaiable
{
$("#box").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('This email name Already exists have you forgot your password? ').addClass('messageboxerror').fadeTo(900,1);
var email_ready = false;
});
}
else
{
$("#box").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Tezac Hamra').addClass('messageboxok').fadeTo(900,1);
var email_ready = true;
});
}
});
});
});
你有一個巨大的多餘的代碼量。 我建議你創建一個函數來顯示消息,因爲所有正在改變的是「email」和「username」字樣 關於來自AlienWebguy的消息,請閱讀[prop](http://api.jquery.com/prop /) – mplungjan