我用WebView加载URL后,我可以插入表单页面中的一些数据在汽车?加载URL后用WebView将数据插入表单
我试着用:
@Override
public void onPageFinished(WebView view, String url) {
String user="pippo";
String pwd="secret";
view.loadUrl("javascript:document.getElementById('j_username').value = '"+user+"';document.getElementById('j_password').value='"+pwd+"';");
}
但不会工作。
的HTML源代码是:
<html>
....
<form action="/.../" method="post">
<table align="center">
<tr>
<td>
<table>
<tr>
<td>User:</td>
<td><input name="j_username" type="text" tabindex="1"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="j_password" type="password" tabindex="2"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Login" tabindex="3"></td>
</tr>
</table>
</td>
</tr>
</table>
<!--</form>-->
</form>
...
<\html>
你是哪里的两种形式指定ID为j_username?我只看到名称,类型和tabindex属性.. –
ops yes..i必须使用document.getElementByName? –
getElementByName()不存在,您必须使用getElementsByName,它将返回一个集合,并且您必须获取用于用户名的位置[0]和用于密码的位置[1]中的元素。只有这两个名称属性是您加载的html页面中的前两个时,这才会起作用。我强烈建议你使用id属性,如果你可以更改html,它们更精确,并且如果添加html代码将不会改变.. –