Article Introduction: today in writing a change to the picture width of the demo encountered a problem, I passed the image object, directly set the property image.style.width=100, not effective, and then find out why, because the Style.width received as a string, Image.width=100, this kind of writing is OK, because the width itself is number type. |
Today in writing a change to the picture width of the demo encountered a problem, I passed the image object, directly set the property image.style.width=100, not effective, and then find out why, because the Style.width received as a string, Image.width=100, this kind of writing is OK, because the width itself is number type.
And then see a set of values about the Style.width, as follows
Ie
Id.style.width = "100"; With numeric value only, no error
Id.style.width = "100px"; With values and units, no errors
Id.style.width = "100px;"; With values, units, and semicolons, an error occurs
Ff
Id.style.width = "100"; With only numeric values, there will be an error
Id.style.width = "100px"; With values and units, no errors
Id.style.width = "100px;"; With values, units, and semicolons, no errors
So we usually write, it is best to use the "number + units" of this type of writing, in order to avoid unexpected errors.