WebView抓取表单数据
我编写了一个混合了 HTML5 和 Android 代码的混合应用程序 - 它运行良好,但我遇到了一些问题。
我们的应用程序有一个供人们填写的表格(带有复选框和相应的数据以及评论部分)。该人可以单击每个复选框,但我需要填充单击的项目,获取他们选择的数据以及他们发表的评论。
最好的方法是什么?供参考:数据仅在表格中列出,每个表格的复选框数量发生变化。但它们都与同一件事相关(或同一类)。
我已经编写了一个 javascript 界面,但在找出解析表单数据的最佳方法时遇到问题。
谢谢!
<form>
<div id="colors">
<table>
<tr>
<th>More header</th><th>NOHTING</th><th>Header</th><th></th>
</tr>
<tr>
<label for="checkbox1" id="checkbox-0">
<td class="stock">1261561</td>
<td class="etete">whatever</td>
<td class="gtgtg">random data</td>
</label>
<td class="add"><input type="checkbox" value="1" checked /></td>
</tr>
<tr>
<label for="checkbox2" id="checkbox-1">
<td class="stock">1261563</td>
<td class="etete">something</td>
<td class="gtgtg">details here</td>
</label>
<td class="add"><input type="checkbox" value="2" checked /></td>
</tr>
<tr>
<label for="checkbox3" id="checkbox-2">
<td class="stock">1261529</td>
<td class="etete">blah</td>
<td class="qtqtq">blah blah</td>
</label>
<td class="add"><input type="checkbox" value="3" checked /></td>
</tr>
<input type="hidden" id="hidden1" value="xxxxxx" />
<input type="hidden" id="hidden2" value="xxxxxxxxxx" />
<input type="hidden" id="hidden3" value="" />
<input type="hidden" id="fah21" value="x" />
<input type="hidden" id="asdf1" value="xxxx,xxx,xx" />
</table>
</div>
<div id="footer">
<textarea placeholder="Add Your Comments..."></textarea>
<div id="cancel">
<img src="../images/cancel.png" height="50px" width="260px" onclick="goBack()">
</div>
<div id="save">
<img src="../images/save.png" width="260px" height="100px" onClick="parseForm()" />
</div>
</div>
</form>
parseForm() 是我无法弄清楚的。
类的名称和数据已更改。另外,当用户单击复选框时,将调用此脚本:
$(document).ready(function(){
$('input[type=checkbox]').tzCheckbox({labels:['Add to whatever','Click to Add']});
});
javascript 接口可以获取任何数据,无论是 JSON、原始数据还是其他任何数据 - 我将修复我的代码以使其正常工作。
I've written a blended application that is a mix between HTML5 and android code - It's working well but I'm having a few issues.
Our application has a form that people will fill out, (with checkboxes and corresponding data and a comment section). The person can click each check box, but I need to populate the items the clicked, grab the data they were selecting and the comments they made.
What is the best way to do this? For reference: The data is just listed in a table and the number of check boxes changes per form. They all are related to the same thing though (or same class).
I've written a javascript interface, but I'm having issues figuring out the best way to parse the form data.
Thanks!
<form>
<div id="colors">
<table>
<tr>
<th>More header</th><th>NOHTING</th><th>Header</th><th></th>
</tr>
<tr>
<label for="checkbox1" id="checkbox-0">
<td class="stock">1261561</td>
<td class="etete">whatever</td>
<td class="gtgtg">random data</td>
</label>
<td class="add"><input type="checkbox" value="1" checked /></td>
</tr>
<tr>
<label for="checkbox2" id="checkbox-1">
<td class="stock">1261563</td>
<td class="etete">something</td>
<td class="gtgtg">details here</td>
</label>
<td class="add"><input type="checkbox" value="2" checked /></td>
</tr>
<tr>
<label for="checkbox3" id="checkbox-2">
<td class="stock">1261529</td>
<td class="etete">blah</td>
<td class="qtqtq">blah blah</td>
</label>
<td class="add"><input type="checkbox" value="3" checked /></td>
</tr>
<input type="hidden" id="hidden1" value="xxxxxx" />
<input type="hidden" id="hidden2" value="xxxxxxxxxx" />
<input type="hidden" id="hidden3" value="" />
<input type="hidden" id="fah21" value="x" />
<input type="hidden" id="asdf1" value="xxxx,xxx,xx" />
</table>
</div>
<div id="footer">
<textarea placeholder="Add Your Comments..."></textarea>
<div id="cancel">
<img src="../images/cancel.png" height="50px" width="260px" onclick="goBack()">
</div>
<div id="save">
<img src="../images/save.png" width="260px" height="100px" onClick="parseForm()" />
</div>
</div>
</form>
parseForm() is what I can't figure out.
The names of classes and the data have been changed. Also, when a user clicks the checkboxes, this script is called:
$(document).ready(function(){
$('input[type=checkbox]').tzCheckbox({labels:['Add to whatever','Click to Add']});
});
The javascript interface can take any data, whether its JSON, raw or anything - I'll fix my code to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是包含一个 JQuery 函数,如下所示:
在代码中包含该函数后,为其编写一个 javascript 接口并附加它,如下所示:
然后在代码中也添加此函数:
注意,这将是最好接受 parseFormData() 中的数据并将数据发送到 ASync 进程,以防止 UIThread 锁定。一定要这样做!
The easiest way to do this is to include a JQuery function as follows:
Once you have that in your code, write a javascript interface for it and attach it like so:
Then in your code, add this as well:
Note, it would be best to accept the data in the parseFormData() and send the data to an ASync process to prevent the UIThread from locking up. Be sure you do this!