最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to simulate input disabled? - Stack Overflow

programmeradmin4浏览0评论

I would like simulate input disabled. I would like don't have change value in input, but this value should be send with POST with FORM.

<input class="dis" type="text" disabled="disabled" value="111">
<input class="no" type="text">
<input class="dis" type="text" disabled="disabled" value="333">

​ /

I can use also CSS and jQuery, but how?

I would like simulate input disabled. I would like don't have change value in input, but this value should be send with POST with FORM.

<input class="dis" type="text" disabled="disabled" value="111">
<input class="no" type="text">
<input class="dis" type="text" disabled="disabled" value="333">

​ http://jsfiddle.net/hC4WP/

I can use also CSS and jQuery, but how?

Share Improve this question edited Apr 19, 2012 at 10:30 Felix Kling 816k180 gold badges1.1k silver badges1.2k bronze badges asked Apr 19, 2012 at 10:27 Ron ForzesteringRon Forzestering 872 silver badges5 bronze badges 3
  • 3 Mark the field as readonly. – Felix Kling Commented Apr 19, 2012 at 10:29
  • possible duplicate of submit disabled fields – Felix Kling Commented Apr 19, 2012 at 10:31
  • I know this is an old thread but... Attribute readonly allows you to modify it. You should do something like this: stackoverflow.com/questions/368813/… – Sonhja Commented Sep 21, 2017 at 13:50
Add a comment  | 

3 Answers 3

Reset to default 12

Use the readonly attribute instead of disabled.

However, this will not result in the field being grayed out. To achieve this, use the following CSS:

input[readonly] { color: #aaa; }

(you might have to change the color a bit to look more like the original disabled color)

Use readonly instead of disabled

Solution with tabindex.

Create a .disabled class.

CSS:

.disabled {
    pointer-events:none; /* No cursor */
    background-color: #eee; /* Gray background */
}

JS:

$(".disabled").attr("tabindex", "-1");

HTML:

<input type="text" class="disabled" />
发布评论

评论列表(0)

  1. 暂无评论