问题
I have this div:
<div id="libraryDisplay">asdf</div>
and this code:
$('#libraryDisplay').val(booksList);
and booksList is a string. It's still displaying "asdf". Any suggestions?
回答1:
val is for form elements. If you're trying to set the text of the <div>
, use text instead:
$('#libraryDisplay').text(booksList);
If booksList
is actually an HTML fragment (and you're reasonably sure it's coming from a safe source and doesn't have the potential to corrupt your page) use html:
$('#libraryDisplay').html(booksList);
回答2:
Try
$('#libraryDisplay').html(booksList);
来源:https://stackoverflow.com/questions/21294992/change-value-of-div-using-jquery-val-not-working