简体   繁体   中英

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.

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'")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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