文档.getElementById与SMARTY变量


document.getElementById with SMARTY Variable

我需要将.innerHTML从具有SMARTY变量作为ID的div中取出。

它看起来像这样:

<div id="{$products_data.IMAGE}">{$products_data.QTY}</div>

到目前为止我尝试过的,由于某种原因不能工作的是:

test = document.getElementById("{$products_data.IMAGE}").innerHTML;

谁有SMARTY和Javascript的经验?

在.tpl文件中使用全局JavaScript变量来传递Smarty的值。

。tpl 文件:

<script>
// Global variables 
var smartyDivId = "{$products_data.IMAGE}";
</script>
.js文件中:
if (typeof smartyDivId != undefined) {
    test = document.getElementById(smartyDivId).innerHTML;
}