Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)?

Here's the relevant HTML of the page

<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>

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".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
172 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...