我用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代碼將不會改變.. –