從單擊它的html表行中預(yù)填充表單字段。(所有這些都應(yīng)該在jsp上發(fā)生)
始終將這些用于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.4tl426be.cn/resources/demos/style.css' />解決方法
我正在嘗試使用jquery或javascript用單擊行選擇的行元素填充表單字段。我嘗試了在stackoverflow上找到的解決方案,以解決類似問題。我是新手,請(qǐng)多多包涵。(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); }});
相關(guān)文章:
1. 數(shù)組按鍵值封裝!2. docker不顯示端口映射呢?3. java - 阿里的開發(fā)手冊(cè)中為什么禁用map來作為查詢的接受類?4. java怎么獲取用戶客戶端mac地址5. java - 無法執(zhí)行該操作,因?yàn)殒溄臃?wù)器 "***" 的 OLE DB 訪問接口 "SQLNCLI" 無法啟動(dòng)分布式事務(wù)。解決方法?6. javascript - 使用vue官方腳手架進(jìn)行單元測(cè)試,如何覆蓋到watch里的變量?7. javascript - 為什么創(chuàng)建多行多列的表格最后只有一行內(nèi)有表格8. javascript - ES6規(guī)范下 repeat 函數(shù)報(bào)錯(cuò) Invalid count value9. clone - git sourceTree克隆倉庫時(shí),都不停彈出Password Required彈窗,即時(shí)輸入正確的git賬號(hào)密碼還是彈出10. html5 - 使用echarts中的圖表 一個(gè)頁面導(dǎo)入了好幾個(gè)js圖表 實(shí)現(xiàn)echarts圖表隨著瀏覽器窗口變化而變化時(shí)出現(xiàn)了問題
