【发布时间】:2011-03-05 23:14:17
【问题描述】:
在我的应用程序中,我希望能够让用户在自定义视图中输入他们的登录信息,然后显示 UIWebView。我希望 UIWebView 以编程方式填写用户的用户名和密码。然后 UIWebView 应该以编程方式单击登录按钮。我一直在尝试:
[webView stringByEvaluatingJavaScriptFromString:@"document.L_lbsc_txtUserName.text.value='ANdrew';"];
但它不起作用。我真的不明白 stringByEvaluatingJavaScriptFromString 的工作原理或它的设计目的。
我认为这可能与我在上面的字符串字段中填写的内容有关。 这是我要访问的网站的源代码:
<div class="lgntxt">
<div style="padding-left:3px;">
<input name="L$lbsc$txtUserName" type="text" value=" -username-" size="10" id="L_lbsc_txtUserName" tabindex="1" class="textbox" onfocus="if(this.value == ' -username-') this.value = ''; Hide('L_lbsc_txtPasswordHelp'); Show('L_lbsc_txtPassword');" onblur="if(this.value == '') this.value = ' -username-';" style="width:80px;"><br>
<img src="/podium/images/spacer.gif" border="0" width="3" height="1"><br>
<input name="L$lbsc$txtPasswordHelp" type="text" value=" -password-" size="10" id="L_lbsc_txtPasswordHelp" tabindex="1" class="textbox" onfocus="Hide('L_lbsc_txtPasswordHelp'); Show('L_lbsc_txtPassword'); document.getElementById('L_lbsc_txtPassword').focus();" style="width:80px;display:;">
<input name="L$lbsc$txtPassword" type="password" size="10" id="L_lbsc_txtPassword" tabindex="2" class="textbox" onkeydown="if ((event.which ? event.which : event.keyCode) == 13) {return false;};" onkeyup="if ((event.which ? event.which : event.keyCode) == 13) {__doPostBack('L$lbsc$btnLogin','');return false;};" onblur="if(this.value == '') {Show('L_lbsc_txtPasswordHelp'); Hide('L_lbsc_txtPassword');}" style="width:80px;display:none;">
</div>
</div>
我正在尝试替换用户名和密码字段。
任何帮助将不胜感激。 提前致谢。
编辑 所以我已经尝试了这些,但它们都不起作用:
[webView stringByEvaluatingJavaScriptFromString:@"document.myForm.myText.value='text from Obj-C';"];
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('L$lbsc$txtUserName').value='ANdrew';"];
【问题讨论】:
标签: javascript objective-c login uiwebview nsstring