简体   繁体   中英

echoing document.getElementById() with php variable as id

Hi I have a list of buttons with different id's like b_1, b_2, b_3 and so on. After that I have PHP code to interact with the database and get my results. Then I have created a variable that receives the identity of the rows that it finds in the table. I would like to use the result to change the background color of the different buttons. It works fine if I write the literal identity "b_1" or "b_2" and so on but not in the form of a variable ($trans_boton). I have tried in many ways and I can't find the key. Thanks for lighting.

$trans_boton = 'b_'.$data['numero'];

if($facta == $respuesta){
echo "<script>"; echo "document.getElementById('b_1').style.backgroundColor='red';"; echo "</script>";}

您只需将 $trans_boton 放在引号中,即:

echo "document.getElementById('$trans_boton')" ;

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