简体   繁体   English

iOS或Android:JavaScript替换属性值

[英]iOS or Android: Javascript replace attribute value

I can easily replace value of html if I know id by writing something like this in android. 我可以通过在android中编写类似的代码轻松地替换html的值(​​如果我知道id的话)。

webView.stringByEvaluatingJavaScript(from: "document.getElementById('Login_loginField').value = 'joni'")

Problem is that now I have a bit complicated attribute like this. 问题是现在我有点像这样的复杂属性。

<input type="text" class="quantumWizTextinputPaperinputInput exportInput" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="Employee ID" aria-describedby="i.desc.1563426530 i.err.1563426530" name="entry.1911914324" value="" required="" dir="auto" data-initial-dir="auto" data-initial-value="something" badinput="false" aria-invalid="false">

I don't know my id and I need to change data-initial-value if it is something . 我不知道我的身份证,我需要改变的数据初始值,如果它是什么 How shall I do? 我该怎么办?

如果类名是唯一的,则可以通过类名进行相同的操作:

webView.stringByEvaluatingJavaScript(from: "document.getElementsByClassName('quantumWizTextinputPaperinputInput exportInput')[0].value = 'joni'")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM