Home > front end >  How the object HTMLDivElement converted to the text
How the object HTMLDivElement converted to the text

Time:09-18

, I have tried many options are output is always the object HTMLDivElement],
The code is as follows:
The function addproduct () {
Var pname=$(" # pname "). The HTML ();
Var price=document. GetElementById (" price "). The innerText;
Var quantity=document. GetElementById (" quantity "). The innerText;
Var stock=document. GetElementById (" stock "). The innerText;
The table ();

}

The function table () {
Var table=document. GetElementById (" cart ");
Var row=table. The insertRow (1);
Var cell1=row. InsertCell (0);
Var cell2=row. InsertCell (1);
Var cell3=row. InsertCell (2);
Var cell4=row. InsertCell (3);
Var cell5=row. InsertCell (4);
Cell1. The innerText=pname;
Cell2. The innerText=price;
Cell3. The innerText=quantity;
Cell4. The innerText=stock;
Cell5. The innerText=price;
}
</script>

CodePudding user response:

I tried to use jquery HTML (), or wrong at the end of the day

CodePudding user response:

 
When you visit in a function within another function of the local variable not, of course, the two functions into one can

The function addproduct () {
Var pname=$(" # pname "). The HTML ();
Var price=document. GetElementById (" price "). The innerText;
Var quantity=document. GetElementById (" quantity "). The innerText;
Var stock=document. GetElementById (" stock "). The innerText;
Var table=document. GetElementById (" cart ");
Var row=table. The insertRow (1);
Var cell1=row. InsertCell (0);
Var cell2=row. InsertCell (1);
Var cell3=row. InsertCell (2);
Var cell4=row. InsertCell (3);
Var cell5=row. InsertCell (4);
Cell1. The innerText=pname;
Cell2. The innerText=price;
Cell3. The innerText=quantity;
Cell4. The innerText=stock;
Cell5. The innerText=price;
}

CodePudding user response:

Can also put the pname price quantity stock these four set to global variables,
Or through a function parameter,

  • Related