从objective-C更改`< input>`元素属性 [英] Change `<input>` element attributes from objective-C

查看:143
本文介绍了从objective-C更改`< input>`元素属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在< input type =checkbox> 元素的值c>从 null 已检查

如何从objective-C执行此操作( iOS应用程序)?

I'm trying to change the value of an element in a <input type="checkbox"> from null to checked.
How would I do this from objective-C (iOS application)?

这是页面的相关 HTML

<td align="right" width="15%" class="darkNeutral">
    <input id="chk_Assignments" type="checkbox" class="ShowAll" />
    <label for="chk_Assignments">Show All</label>

    &nbsp;&nbsp;
</td>

我以为我会用 POST 或其他什么,但我不知道如何访问该元素,添加已检查属性,并将该属性的值设置为已选中

I was thinking I'd use POST or something, but I'm not sure how to access the element, add a checked attribute, and set the value of the attribute to "checked".

推荐答案

NSString *javaScript = @"document.getElementById('chk_Assignments').setAttribute('checked', 'checked');";

// Make the UIWebView method call
NSString *response = [webViewA stringByEvaluatingJavaScriptFromString:javaScript];
NSLog(@"javascript result: %@", response);

如果HTML页面包含了jQuery,则可以简化javascript:

If HTML page got jQuery included, the javascript could be simplified:

NSString *javaScript = @"$('#chk_Assignments').attr('checked', 'checked');";
NSString *response = [webViewA stringByEvaluatingJavaScriptFromString:javaScript];
NSLog(@"javascript result: %@", response);

这篇关于从objective-C更改`&lt; input&gt;`元素属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆