2014-03-25 38 views
0

我有很多字段的大表單,現在我想使用JavaScript來簡化字段,這意味着,預處理並刪除一些JavaScript字段,然後返回一個新的處理字段。如何用JavaScript修改表單域?

例如,我有字段等形式plot_countryplot_stateplot_city,我想要做的是從預先計算在JavaScript中country, state, citylocation_#,並返回GET場只包含location_#

通過這種方式,URL將被簡化,服務器可以直接使用location_#,並且不需要再處理位置組合。

有沒有人有一些想法?謝謝!

+0

代碼?你有什麼嘗試? –

回答

0

嘗試是這樣的:

<form id="location_form"> 
<input type="text" id="plot_country"> 
<input type="text" id="plot_state"> 
<input type="text" id="plot_city"> 
<input type="hidden" id="location"> 
<input type="submit"> 
</form> 

<script type="text/javascript"> 
    $("#location_form").submit(function(event) { 
     $('#location').value($(this).serialize()); 
     $('input[type=text]').remove(); 
    }); 
</script>