When assigning an object to an HTML tag's properties today, it is a bit strange to find that the value taken is [Object,object].
The code is as follows:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title>[Object Object]</title>6 <Scripttype= "Text/javascript"src=".. /.. /trd/jquery/jquery-1.9.1.min.js "></Script>7 <Scripttype= "Text/javascript">8 $(function(){9 varStudent={name:"Xiao Ming", Gender:"male"};Ten $("#txt"). attr ("RowData", student);//Add the RowData property to the label with the ID txt and the value to the student object One A Console.log ($ ("#txt"). attr ("RowData"));//console output is: [Object Object] - Alert ($ ("#txt"). attr ("RowData"));//The information in the popup box is: [Object Object] - }); the </Script> - </Head> - <Body> - <inputtype= "text"name= "txt"ID= "txt"/> + </Body> - </HTML>
So how do you get the value of an object? My practice is to assign values by first converting the student object to a JSON string using the Json.stringify method.
The code is as follows:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title>[Object Object]</title>6 <Scripttype= "Text/javascript"src=".. /.. /trd/jquery/jquery-1.9.1.min.js "></Script>7 <Scripttype= "Text/javascript">8 $(function(){9 varStudent={name:"Xiao Ming", Gender:"male"};Ten $("#txt"). attr ("RowData", json.stringify (student));//Add the RowData property to the label with the ID txt and the value to the student object One A Console.log ($ ("#txt"). attr ("RowData"));//Console output is: {"name": "Xiaoming", "gender": "Male"} - Alert ($ ("#txt"). attr ("RowData"));//The information in the popup box is: {"name": "Xiaoming", "gender": "Male"} - }); the </Script> - </Head> - <Body> - <inputtype= "text"name= "txt"ID= "txt"/> + </Body> - </HTML>
But I have another question is: Why the alert (object) output value is [Object,object], if you see this article Bo friends know the answer, but also hope to enlighten.
JavaScript [Object,object]