简体   繁体   English

只读文本的HTML标签

[英]HTML label for read only text

Which html element should I use when using a Label for text? 使用Label文本时我应该使用哪个html元素?

I need to set the text of the element to a client name that is selected from an jqueryui autocomplete control. 我需要将元素的文本设置为从jqueryui自动完成控件中选择的客户端名称。

I've tried using a span, which works in Chrome but not in IE. 我尝试使用跨度,它适用于Chrome,但不适用于IE。 Is there a recommended way of doing this? 有推荐的方法吗?

html: HTML:

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

autocomplete javascript: 自动完成javascript:

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

Input with type text has a text value and a readonly property. 带有文本类型的输入具有文本值和readonly属性。 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. .val()方法用于获取表单元素的值,例如input,select和textarea。 You are trying to use val() on a span which obviously doesn't work. 你试图在一个显然不起作用的跨度上使用val()。

Replace it with a readonly input or store the ID in another hidden input element. 将其替换为只读输入或将ID存储在另一个隐藏的输入元素中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM