douzhannao5357 2018-10-22 06:31
浏览 54

要在html代码中注入的Javascript变量

The Scope of my project is to translate several webpages on a different language. I created a table in MS SQL DB with the first column as element ID (e.g. el0). The Other columns represent text translation, each column with different language lets say on the same row (el0) in English I got a string "Group" on the next column lets say it is German the string "Gruppe". I got an intranet site used for reporting, and on this website I want to implement a language dropdown list, what will translate the webpage on a desired format. At the moment the webpage is already created and the text is static for each menu. I got a query what is running at the load phase of the webpage and returns from the DB a multidimensional array in php.

    Array
(
    [0] => Array
        (
            [0] => el1
            [1] => Grouping
        )

    [1] => Array
        (
            [0] => el2
            [1] => Type
        )

    [2] => Array
        (
            [0] => el3
            [1] => Starting Date
        )

    [3] => Array
        (
            [0] => el4
            [1] => Ending Date
        )

    [4] => Array
        (
            [0] => el5
            [1] => Section
        )

    [5] => Array
        (
            [0] => el6
            [1] => Cell
        )

    [6] => Array
        (
            [0] => el7
            [1] => Client
        )

    [7] => Array
        (
            [0] => el8
            [1] => Status
        )

    [8] => Array
        (
            [0] => el9
            [1] => Article
        )

    [9] => Array
        (
            [0] => el10
            [1] => Search
        )

)

I had transformed this array in javascript first value as new variable and the second value as the value of the newly created variable.

foreach ($language_array as $value) {
  echo "<script> var ".$value[0]." = ". json_encode($value[1]).";</script>";
    }

I was thinking that in this way I will be able to insert javascript variable in html for each static quest, but it seems I can't use the way I was thinking e.g.:

<script>document.write(el0);</script>

a part of the html page where I want to use the variable values:

<tr>    
    <td colspan ="8" align="center" class="first">***variable value from el1***</td>
    <td colspan ="8" align="center" class="first">***variable value from el2***</td>
    <td colspan="3" align="center" class='first'>***variable value from el3***</td>
    <td colspan="3" align="center" class='first'>***variable value from el3***</td>
</tr>

please assist me how can I fulfill the requirements?

Thanks

Ervin

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c