2013-10-29 40 views

回答

2

沒有JavaScript是不可能的。 使用JavaScript,您可以編寫自己的.onsubmit()處理程序,並將此元素注入到表單數據中。 你也可以使用ajax來處理表單提交和回覆並處理響應。上JS

實施例與jQuery庫.onsubmit()和元件注射:

使用example.php:

輸出輸入後
<html> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
</head> 
<body> 
    <?php 
    if(sizeof($_POST)>0) 
     var_dump($_POST); 
    ?> 
    <input type="hidden" name="hidden_field_1" value="hidden value"> 
    <form action="example.php" method="post" name="form1"> 
     <input type="text" name="visible_text_field"> 
     <input type="submit" value="Submit form"> 
    </form> 
    <script> 
    $(function(){ 
     $('form[name=form1]').on('submit', function(e){ 
      var hidden_input = $('input[name=hidden_field_1]'); 
      $('form[name=form1]').append(hidden_input); 
     }); 
    }); 
    </script> 
    </body> 
</html> 

和提交:

array(2) { 
    ["visible_text_field"]=> 
    string(10) "test input" 
    ["hidden_field_1"]=> 
    string(12) "hidden value" 
} 
0

用JavaScript,你可以得到這樣的值,

var mytextvalue = document.getElementById("mytext").value 
0

你有兩個選擇去 jQuery的

var buttonval = $("#buttonid").val(); 

用JavaScript

var buttonvalue = document.getElementById("buttonid").value;