问题
The append cmd doesn't close my tags, but why?
What do i have to change?
for (var i = 0; i<=4; i++)
$("#wrapper").append('<li id=img'+i+'></li>');
This always creates only <li id=img1>
, but no </li>
?!
回答1:
Your code should be:
for (var i = 0; i<=4; i++)
$("#wrapper").append('<li id="img'+i+'"></li>');
I think you forgot the quotes for the id attribute
回答2:
The code you provided does seem to add the tags you want.
If I run the exact javascript you provided, viewing generated source using the web developer toolbar in firefox gives me <li id="img2"></li>
and inspecting the element in firebug shows me <li id="img2"/>
.
Both of those are closed and proper xhtml. Though if you aren't using xhtml, the closing tag isn't required anyway.
来源:https://stackoverflow.com/questions/1437870/does-jquery-append-close-html-tags