从单击它的html表行中预填充表单字段。(所有这些都应该在jsp上发生)
始终将这些用于js和ui部分。
<link rel='stylesheet' href='http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css' /><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='https://www.haobala.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. 视频文件不能播放,怎么办?2. mysql - 把一个表中的数据count更新到另一个表里?3. 请教使用PDO连接MSSQL数据库插入是乱码问题?4. mysql 查询身份证号字段值有效的数据5. visual-studio - Python OpenCV: 奇怪的自动补全问题6. mysql - 分库分表、分区、读写分离 这些都是用在什么场景下 ,会带来哪些效率或者其他方面的好处7. node.js - nodejs开发中常用的连接mysql的库8. python bottle跑起来以后,定时执行的任务为什么每次都重复(多)执行一次?9. python - 爬虫模拟登录后,爬取csdn后台文章列表遇到的问题10. Python爬虫如何爬取span和span中间的内容并分别存入字典里?
