简体   繁体   中英

JQuery script to fill textbox / input based on class

I'm looking to craft a JQuery script to fill all textboxes on a page with a single string of text.

The textboxes on this page have no name or ID, so I need to fill them in by class.

<td>
    <input class="form-control input-sm" placeholder="Optional Comment" value="" style="">
</td>

Thank you everyone.

Are you familiar with vanilla JS DOM manipulation?

var allTextboxes = document.querySelectorAll(".CLASS_SELECTOR");

for(var i = 0, len = allTextboxes.length; i < len; i++){
    allTextboxes[i].value = "YOUR_VALUE";
}

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