简体   繁体   中英

selecting field text with javascript

I am using the below code to select a fields text with JavaScript but it doesn't quite work:

//auto select that fields text for easy COPY

var content = parent.document.getElementById('share_field_<?php echo $id; ?>');
content.focus();
content.select();

Field to select:

//share field

echo '<div class="name" style="display: none" id="share_field_'.$row['id'].'"><input name="share" type="text" value="http://www.site.com/play/'.$row['id'].'" size="53"></div>';

I think you should use something like this:

var content = parent.document.getElementById('share_field_<?php echo $id; ?>');
content.firstChild.focus();
content.firstChild.select();

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