Description of requirements: The page can dynamically add data, such as table, click the button can dynamically join the row.
Again or page
When loading the table data is obtained through Ajax from the background. And then we want to get a value in it, and how to get it?
Suppose that you want to get an analogy click,mouseover through an event, and so on, you can use the Live() method
$ (". Button"). Live ("Click", Function () { Console.info ($ ("#mytd"). html ());
Specific instructions for live () http://blog.csdn.net/itmyhome1990/article/details/17380665
And assuming it's not an event, we're going to get the value or do something else when the page loads.
The live () method is not available because we cannot pass in an event.
For example, the following code:
<body><table id= "tab" border= "1" width= "30%" ></table></body><script type= "text/ JavaScript ">$ (function () { $.post (" Admin/userforumthemebabygrowupfrontlist.do ", {},function (data) { Console.info (data.table); $ ("#tab"). Append (data.table); }) Alert ($ ("#mytd"). html ());//Get value});</script>
The above code is very easy, that is, the value returned by post from the background is added to <table>
Background return data for <TR><TD id= ' mytd ' > Beijing </td><td> shenzhen </td></tr> and we're going to get a value with ID MYTD after post,
This is not available at this point, and we can see the problem from the browser:
From the above can be seen in the alert when the data is not yet loaded out of the console also did not print out the information, so this time is not data.
using the Ajaxcomplete () method to run the code to run when the request is complete , we change to such as the following:
$ (function () {$.post ("admin/userforumthemebabygrowupfrontlist.do", {},function (data) {console.info (data.table); $ ( "#tab"). Append (data.table);}) $ ("#tab"). Ajaxcomplete (function () { //To Run alert ($ ("#mytd") when the request is complete. HTML ());});
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvaxrtewhvbwuxotkw/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>
At this point, the page has loaded the data when it is retrieved.
jquery gets dynamically generated elements