简体   繁体   English

如何从 jquery 中的数据属性获取 json 解码值

[英]How to get json decode value from data attribute in jquery

I am working with jquery and right now i am passing "Php array with json encode" in "data attribute" and right now i am trying to get this (json encode) value in jquery, But right now i am getting "new" (after update/new) value instead of existing,How can i do this?我正在使用 jquery,现在我在“数据属性”中传递“带有 json 编码的 Php 数组”,现在我试图在 jquery 中获取这个(json 编码)值,但现在我正在获取“新”(在更新/新)值而不是现有值之后,我该怎么做? Here is my current code这是我当前的代码

 echo '<td class=try contenteditable="true" data-id="'.$id.'" data-txt="'.json_encode($col).'">'; //$col is array



   <script>
        $("td").keypress(function(e){
            var id = $(this).attr("data-id")
            var newtxt = $(this).attr("data-txt")
             var oldtext = $(this).text();
                 if(e.which == 13) {
                alert('oldtext is '+oldtext);   
            }
     });
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM