使ReadOnly文本框不可选 [英] Make ReadOnly Textbox Non-Selectable

查看:115
本文介绍了使ReadOnly文本框不可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有只读属性的文本框。这不是什么大问题,但我想我会问,那么有没有办法让这个文本框,以便用户不能选择它并将其光标放在它?



禁用属性会这样做,但那个文本框不会与表单一起提交。



是否有js / jquery解决方案?



SNIPPET






 <形式> 
< div class =col-md-9>
@ Html.EditorFor(model => model.Time,new {htmlAttributes = new {@class =form-control clear-textbox create-form-txtbox time-txtbox,@readonly =readonly} })
@ Html.ValidationMessageFor(model => model.Time,,new {@class =text-danger})
< / div>

< input type =submitvalue =Submit/>
< / form>






任何帮助表示感谢。

解决方案

我已经使用Stephen的评论作为答案,并且工作正常。

一个隐藏的输入字段提交给服务器,但用户将只能看到隐藏输入字段持有的值的禁用文本框。


I have a form with a textbox that has an attribute of read-only. This isn't a big deal but I thought I would ask, so is there a way to make that textbox so that the user cannot select it and put their cursor in it?

The disabled attribute does that, but then that textbox doesn't get submitted with the form.

Is there a js/jquery solution for this?

SNIPPET


<form>
    <div class="col-md-9">
        @Html.EditorFor(model => model.Time, new { htmlAttributes = new { @class = "form-control clear-textbox create-form-txtbox time-txtbox", @readonly = "readonly" } })
        @Html.ValidationMessageFor(model => model.Time, "", new { @class = "text-danger" })
    </div>

    <input type="submit" value="Submit" />
</form>


Any help is appreciated.

解决方案

I have used Stephen's comment as an answer and it works.

I have created a hidden input field to submit to the server, but the user will only see the disabled textbox with the value that that hidden input field is holding.

这篇关于使ReadOnly文本框不可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆