简体   繁体   中英

JavaScript call function with PHP-Variable as transfer parameter

I am calling the JavaScript-function getElementById. As transfer parameter I want to use the PHP-Variable $currentTab

var currentTab = document.getElementById(<?php $currentTab ?>);

You need to add quotes, and output your variable with echo . Maybe add the # character if it is not in your php variable

document.getElementById('<?php echo $currentTab; ?>');

只需在' <?php $currentTab ?>周围添加'" ,以使getElementById()接受字符串。而在javascript中,字符串则由'"代替。

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