如何在点击时存储数据

时间:2015-12-13 05:41:22

标签: javascript jquery json

我有一个由json对象检索的输出。我只想点击链接<a href="http://localhost/redmine/projects/'+ value.id+'">'+ value.name+'</a>

,将 value.id 存储到以下变量中

x是变量。

var x = document.getElementById(value.id).value;  
localStorage.setItem("projectID", x);
document.getElementById("result1").innerHTML = localStorage.getItem("projectID"); 

&#13;
&#13;
$.ajax({
      dataType: "jsonp",
      url: "http://localhost/redmine/projects.json",
      //data: $.parseJSON(data),
      success: function(results){
           
            $.each(results.projects, function(i,value) {
              $('.well').append('<h4 class="h5class"><a href="http://localhost/redmine/projects/'+ value.id+'">'+ value.name+'</a>: '+ '<span class="emtext">' +'('+ value.created_on + ')' +'</span>'+ '</h4>'
               + '<p class="hmpclass">'+ value.summary+ '('+ value.description + ')' +'</p>'
                + '<hr class="hrclass">'
                
                ); 

            });

           

        }
    });
&#13;
&#13;
&#13;

JSON对象看起来像吼叫。

{"projects":[{"id":9,"name":"asdasdsa","identifier":"asdsadasdas","description":"asdasdasdas","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date","value":""},{"id":5,"name":"End_date","value":""},{"id":7,"name":"Stack","value":""}],"created_on":"2015-12-13T03:58:17Z","updated_on":"2015-12-13T03:58:17Z"},{"id":8,"name":"this is a new porject","identifier":"this-is-a-new-porject","description":"this is a new porject","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date","value":""},{"id":5,"name":"End_date","value":""},{"id":7,"name":"Stack","value":""}],"created_on":"2015-12-13T03:57:10Z","updated_on":"2015-12-13T03:57:10Z"},{"id":7,"name":"this is a new porject","identifier":"sunday-proejct","description":"this is the new Sunday project.","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date","value":""},{"id":5,"name":"End_date","value":""},{"id":7,"name":"Stack","value":""}],"created_on":"2015-12-13T03:56:07Z","updated_on":"2015-12-13T03:56:07Z"},{"id":5,"name":"This is project name","identifier":"this-is-project-name","description":"This is description","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date"},{"id":5,"name":"End_date"},{"id":7,"name":"Stack"}],"created_on":"2015-12-05T07:40:17Z","updated_on":"2015-12-05T07:40:17Z"},{"id":2,"name":"This is the second project","identifier":"this-is-the-second-project","description":"Note: Some of the font effects (e.g. 3d) do not scale particularly well, and tend to look best when used with larger font sizes. Additionally, you might want to style the fonts further, such as changing the color of the text to match your page.\r\n\r\nThere are many more ways to style your fonts, and many things are possible through CSS. We are simply providing a few ideas to get you started. For more ideas, try Google searching \"css text effects\" and browse through many of the ideas that are already on the web!\r\n\r\nFurther reading\r\n\r\nSee a complete list of font families provided by the Google Fonts API on Google Fonts.\r\nLearn how to use the Web Font Loader to have more control over loading fonts.\r\nLearn more about how the Google Fonts API works on the Technical Considerations page.\r\nExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies.","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date"},{"id":5,"name":"End_date"},{"id":7,"name":"Stack"}],"created_on":"2015-11-21T09:18:17Z","updated_on":"2015-11-21T09:18:17Z"},{"id":6,"name":"THis is the sixth project","identifier":"this-is-the-sixth-project","description":"This is a example description","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date"},{"id":5,"name":"End_date"},{"id":7,"name":"Stack"}],"created_on":"2015-12-07T07:20:00Z","updated_on":"2015-12-07T07:20:00Z"},{"id":3,"name":"This is the Third project","identifier":"this-is-the-third-project","description":"Note: Some of the font effects (e.g. 3d) do not scale particularly well, and tend to look best when used with larger font sizes. Additionally, you might want to style the fonts further, such as changing the color of the text to match your page.\r\n\r\nThere are many more ways to style your fonts, and many things are possible through CSS. We are simply providing a few ideas to get you started. For more ideas, try Google searching \"css text effects\" and browse through many of the ideas that are already on the web!\r\n\r\nFurther reading\r\n\r\nSee a complete list of font families provided by the Google Fonts API on Google Fonts.\r\nLearn how to use the Web Font Loader to have more control over loading fonts.\r\nLearn more about how the Google Fonts API works on the Technical Considerations page.\r\nExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies.","status":1,"is_public":true,"custom_fields":[{"id":4,"name":"Start_date"},{"id":5,"name":"End_date"},{"id":7,"name":"Stack"}],"created_on":"2015-11-21T09:18:36Z","updated_on":"2015-11-21T09:18:36Z"}],"total_count":7,"offset":0,"limit":25}

1 个答案:

答案 0 :(得分:0)

首先解析结果。试试这个

{{1}}