问题描述:

I have a snippit of jquery code that works great(not my code). It works as expected.

How weould I do this if I wanted to populate a text box instead of appending to a dropdownlist.

JQUERY CODE

 $('#ArtistId').append(

$('<option></option>')

.val(data.Artist.ArtistId)

.html(data.Artist.Name)

.prop('selected', true );

TRIED

$('#ArtistTexboxId').append($('<input></input>')

.val(data.Artist.ArtistId)

.html(data.Artist.Name);

网友答案:
$('<input/>')
     .attr({
             id: 'ArtistTexboxId',
             name: data.Artist.Name
          })
    .val(data.Artist.ArtistId)
    .appendTo('#ArtistDiv')​;​

OR

$('#ArtistDiv')
   .append($('<input/>')
                .attr({
                        id: 'ArtistTexboxId',
                         name: data.Artist.Name
                     })
                .val(data.Artist.ArtistId)
          );​

textbox does not have innerHtml

Store that info in the name attribute of the TextBox

Fiddle

相关阅读:
Top