在UIWebView中将Text设置为textarea

时间:2016-01-13 21:18:36

标签: xcode dom uiwebview

我试图在UIWebView中将Text设置为textarea。

<textarea class="GFS3D5JBNW" style="padding: 4px;border-radius: 5px;" placeholder="Some placeholder text ..." title="Some Title ..." tabindex="1"></textarea>

我试过的代码

NSString *source = [NSString stringWithFormat:@"var inputFields = document.getElementsByTagName('textarea'); \
                    for (var i = inputFields.length >>> 0; i--;) { if(inputFields[i].tabindex == '1') inputFields[i].value = '%@';}", text];
[self.mainWebView stringByEvaluatingJavaScriptFromString: source];

 NSString *source = [NSString stringWithFormat:@"var inputFields = document.getElementsByTagName('textarea').value = '%@';}", text];
[self.mainWebView stringByEvaluatingJavaScriptFromString: source];

但没有成功:-(有没有人暗示过我?

1 个答案:

答案 0 :(得分:0)

问题由

解决
NSString *source = [NSString stringWithFormat:@"var inputFields = document.getElementsByTagName('textarea'); \
for (var i = inputFields.length >>> 0; i--;) {inputFields[i].value = '%@';}",input];
[self.mainWebView stringByEvaluatingJavaScriptFromString:source];