admin管理员组

文章数量:1271802

Which html element should I use when using a Label for text?

I need to set the text of the element to a client name that is selected from an jqueryui autoplete control.

I've tried using a span, which works in Chrome but not in IE. Is there a remended way of doing this?

html:

<p>
     <label for="ClientLabel">Client:</label>
     <span id="ClientLabel" style="width: 160px; font-weight: bold;" />
</p>

autoplete javascript:

$('#ClientSearchAutoplete').autoplete(
            {
                source: "/Report/ClientAutopleteJSON",
                select: function (event, ui) {                    
                    $('#ClientLabel').text(ui.item.value);
                    $('#ClientLabel').val(ui.item.id);                        
                }
            });

Which html element should I use when using a Label for text?

I need to set the text of the element to a client name that is selected from an jqueryui autoplete control.

I've tried using a span, which works in Chrome but not in IE. Is there a remended way of doing this?

html:

<p>
     <label for="ClientLabel">Client:</label>
     <span id="ClientLabel" style="width: 160px; font-weight: bold;" />
</p>

autoplete javascript:

$('#ClientSearchAutoplete').autoplete(
            {
                source: "/Report/ClientAutopleteJSON",
                select: function (event, ui) {                    
                    $('#ClientLabel').text(ui.item.value);
                    $('#ClientLabel').val(ui.item.id);                        
                }
            });
Share Improve this question asked Jan 4, 2012 at 7:52 woggleswoggles 7,44413 gold badges77 silver badges132 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Input with type text has a text value and a readonly property. It will look like a input box which you may want to style so as not to confuse the user.

<input type="text" name="ClientName" value="YourValue" readonly="readonly" />

The .val() method is used to get the values of form elements such as input, select and textarea. You are trying to use val() on a span which obviously doesn't work.

Replace it with a readonly input or store the ID in another hidden input element.

本文标签: javascriptHTML label for read only textStack Overflow