2012-03-14 69 views
-1

我是JavaScript新手。如何在HTML表單提交時打印這些值?打印此頁面提交

+0

你有什麼代碼這麼遠?你問過我的朋友Google嗎? – Joseph 2012-03-14 07:05:49

+0

發佈你的代碼,給出更多細節,確切的價值? – slash197 2012-03-14 07:06:00

+1

在屏幕上打印或使用打印機打印?在屏幕本身上打印 – 2012-03-14 07:07:14

回答

0

假設你的形式看起來像:

<form action=""> 
     <input type="text" name="User" /> 
     <input type="password" name="Password"/> 
     <span>Admin</span> <input type="checkbox" name="IsAdmin" /> 
     <span>US</span> <input type="radio" name="Country" value="US" /> 
     <span>UK</span> <input type="radio" name="Country" value="UK" /> 
     <input type="submit" /> 
    </form> 

jQuery代碼看起來應該是這樣的出發點:

<script type="text/javascript"> 
     $(document).ready(function() { 
      $("form").submit(function() { 
       User = $("input[name='User']").val(); 
       Password = $("input[name='Password']").val(); 
       IsAdmin = $("input[name='IsAdmin']").attr("checked"); 
       Country = $("input:radio[name='Country']:checked").val(); /* Special case of radio buttons*/ 

       document.writeln(User); 
       document.writeln(Password); 
       document.writeln(IsAdmin); 
       document.writeln(Country); 

       return false; 
      }) 
     }); 
    </script> 
0

jQuery的代碼如下:

$('#button_ID').submit(function() { 
alert('something'); 
}); 

button_ID是你的提交按鈕的ID,如果你想停止的形式提交再加入返回false;在結束

$('#button_ID').submit(function() { 
alert('something'); 
return false; 
});