以编程方式填写UIWebview中的数据

And*_*rew 3 javascript login objective-c uiwebview nsstring

在我的应用程序中,我希望能够让用户在自定义视图中输入他们的登录信息,然后显示UIWebView.我希望UIWebView以编程方式填入用户的用户名和密码.然后UIWebView应以编程方式单击登录按钮.我一直在努力:

[webView stringByEvaluatingJavaScriptFromString:@"document.L_lbsc_txtUserName.text.value='ANdrew';"];
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我真的不明白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>
Run Code Online (Sandbox Code Playgroud)

我正在尝试替换用户名和密码字段.

任何帮助将不胜感激.提前致谢.

编辑, 所以我尝试了这些,但没有一个工作:

[webView stringByEvaluatingJavaScriptFromString:@"document.myForm.myText.value='text from Obj-C';"];

[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('L$lbsc$txtUserName').value='ANdrew';"];
Run Code Online (Sandbox Code Playgroud)

Jim*_*Jim 5

该方法接受JavaScript,在文档的上下文中执行它,然后将结果返回给您.看来你的JavaScript是错的.尝试:

[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('L$lbsc$txtUserName').value='ANdrew';"];
Run Code Online (Sandbox Code Playgroud)

如果您不确定方法的作用,请转到iOS参考库,找到您正在使用的类的类引用,然后向下滚动到您正在使用的方法的描述.