從單擊它的html表行中預填充表單字段。(所有這些都應該在jsp上發生)
始終將這些用于js和ui部分。
<link rel='stylesheet' /><script src='http://code.jquery.com/jquery-1.8.3.js' type='text/javascript'></script><script src='http://code.jquery.com/ui/1.10.0/jquery-ui.js' type='text/javascript'></script><link rel='stylesheet' href='http://www.intensediesel.com/resources/demos/style.css' />解決方法
我正在嘗試使用jquery或javascript用單擊行選擇的行元素填充表單字段。我嘗試了在stackoverflow上找到的解決方案,以解決類似問題。我是新手,請多多包涵。(http://jsbin.com/rotuni/2/edit)。但是我嘗試了很多次。它無法正常工作。
//html part containing the form fields which is to be pre-populated. <body><form class='data-form'><label>Value1<input /></label><label>Value2<input /></label><label>Value3<input /></label><label>Value4<input /></label></form> <table > <thead><tr> <th>value1</th> <th>value2</th> <th>value3</th> <th>value4</th></tr> </thead> <tbody> </tbody> </table> </body>
js部分
$(function() { var tableData = [ { value1: 'row1-v1',value2: 'row1-v2',value3: 'row1-v3',value4: 'row1-v4' },{ value1: 'row2-v1',value2: 'row2-v2',value3: 'row2-v3',value4: 'row2-v4' } ]; var rows = $.map(tableData,function(rowData) { var row = $('<tr></tr>'); row.append($(’<td class='class1'></td>’).html(rowData.value1)); row.append($(’<td class='class2'></td>’).html(rowData.value2)); row.append($(’<td class='class3'></td>’).html(rowData.value3)); row.append($(’<td class='class4'></td>’).html(rowData.value4)); row.on('click',function() { fillForm(rowData); }); return row; }); $('.data-table').append(rows); function fillForm(rowData) { var form = $('.data-form'); form.find('input.value1').val(rowData.value1); form.find('input.value2').val(rowData.value2); form.find('input.value3').val(rowData.value3); form.find('input.value4').val(rowData.value4); }});
相關文章:
1. mysql - AttributeError: ’module’ object has no attribute ’MatchType’2. javascript - JS設置Video視頻對象的currentTime時出現了問題,IE,Edge,火狐,都可以設置,反而chrom卻...3. javascript - 圖片能在網站顯示,但控制臺仍舊報錯403 (Forbidden)4. MySQL客戶端吃掉了SQL注解?5. 網頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決6. 數據庫 - MySQL 單表500W+數據,查詢超時,如何優化呢?7. objective-c - iOS怎么實現像QQ或者微信的實時推送8. php自學從哪里開始?9. 求大神幫我看看是哪里寫錯了 感謝細心解答10. phpstady在win10上運行
