douzhou7124 2017-01-23 01:08
浏览 1811

javascript获取数组对象中字段的值

I everybody

in my codeigniter structure I have this array of object named $corsi

Array
(
    [0] => stdClass Object
        (
        [id] => 1
        [nome] => abcd
        [costo_mensile] => 5

    )

    [1] => stdClass Object
    (
        [id] => 2
        [nome] => efgh
        [costo_mensile] => 10
    )

)

I want to access this data with javascript or a function javascript its possibile ? can i get for example the field "nome" ?

im try with

echo "('rif_corso', $corsi, '', 'onChange="run();" id="corsi"')

an in a script:

document.getElementById("corsi").value

can something help me ? thanks a lot riccardo

  • 写回答

1条回答 默认 最新

  • dongyan8896 2017-01-23 01:24
    关注

    You can echo the whole js program somewhere into your html:

    For example just before your closing </body> tag (if its possible with CodeIgniter) or some other script injection technique)

    echo "<script>"
    echo "var someVar = " . json_encode($phpVariable) . ";";
    echo "console.log(someVar);";
    echo "</script>";
    echo "</body>";
    

    This is not the way of doing in some proper applications. Just for learning and understanding purposes.

    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题