我想在提交表單之前在兩個輸入字段中清除我的默認值。 但是這不工作...提交表單之前清除值(不取消提交)
<form action="page.html" id="myForm">
<input type="text" value="Firstname" name="firstname" id="firstname">
<input type="text" value="Lastname" name="lastname" id="lastname">
<input type="submit">
</form>
<script>
$(document).ready(function() {
$("myForm").submit(function() {
if($('#firstname').val() == "Firstname")
$('#firstname').val() = "";
if($('#lastname').val() == "Lastname")
$('#lastname').val() = "";
return true;
});
});
</script>
我不想清除它們兩個焦點。 我不能使用html5。
所以你想在焦點的領域,而不是提交? – 2012-02-22 15:10:41