2012-10-31 2 views
7

disabled 속성을 입력에 사용하면 사용자 입력을 방지하고 약간 다른 모양을 트리거 할 수 있습니다.
데모보기 http://jsfiddle.net/D2RLR/3023/부트 스트랩에 입력 할 수 없습니다. 다른 태그에 어떻게 적용합니까?

테이블과 같은 다른 태그에 같은 스타일을 적용하고 싶습니다.
사실 handsontable을 사용하여 Excel-like data grid editor을 생성합니다.
disabled attribute을 다음 문맥 (TAG 같은 표)으로 어떻게 적용 할 수 있습니까? - 사용

.readOnly 셀 속성이 http://handsontable.com/demo/conditional.html

있습니다 :

여기 http://jsfiddle.net/D2RLR/3025/

+1

플러그인 것과 같은, 그렇게 할 몇 가지 옵션을 가지고 있지 않는 당신이 할 수없는 그냥 r 파란색 테두리와 모든 것으로 움직이는 egular 요소. 가장 가까운 것은 플러그인에서 이벤트를 무시하거나 자신 만의 플러그인을 만드는 것입니다. – adeneo

+0

@adeneo 귀하의 의견에 감사드립니다. 어쨌든, 나는 테이블에'disabled attribute'를 적용해서는 안되지만, 손 잡을 수있는 데이터 그리드에 속한 셀을 클릭 할 때 입력 폼에 그것을 적용하는 방법을 찾아야합니다. 어떻게 만드는지? –

답변

6

확인 여기 handsontablebootstrap를 사용하여 데모입니다!

또한 HTML 입력은 readonly 속성을 가지고 있습니다.이 속성은 disabled 속성뿐만 아니라 그 동작간에 상당한 차이가 있습니다. 그래서 당신은 테이블이 같은 속성을 가지고 있지 않기 때문에, 그렇게 부트 스트랩 사용할 수 없습니다

input[disabled], select[disabled], textarea[disabled], input[readonly], select[readonly], textarea[readonly] { 
    background-color: #EEEEEE; 
    cursor: not-allowed; 
} 

:

+0

+1 답변을 보내 주셔서 감사합니다.나는'readOnly cell property'에 대해 이미 알고 있습니다. 어쨌든 내 wuestion 다릅니다. 부트 스트랩처럼이 셀에'disabled inputs' 스타일을 적용하고 싶습니다. –

0

부트 스트랩은 같은 자신의 disabled 속성에 따라 입력을 스타일링한다.

당신은 일종의 플러그인을 사용하거나 자신의 롤을 사용해야합니다.

6

부트 스트랩의 기존 input[disabled] 스타일링을 적용 할 수는 없지만 스타일을 정확히 모방 한 새로운 CSS를 추가 할 수 있습니다.

예를 들어

: (열 및 행 머리글이 같은 색이기 때문에), 그러나

#exampleGrid td { 
    cursor: not-allowed; 
    background-color: #EEE; 
    color: #9E9999; 
} 

은 분명이 당신의 읽기 전용 로직을 포함하지 않으며, looks a little weird with your fiddle은 그것의 요점입니다.

0

어쩌면이게 도움이 될 수 있습니다 ... 세포의 모양을 변경하고 그것에 편집 할 수 있습니다.

HTML

<table class="editableTable"> 
    <thead> 
     <tr> 
      <th>Code</th> 
      <th>Name</th> 
      <th>E-mail</th> 
      <th>Telephone</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>001</td> 
      <td>João Carlos</td> 
      <td>[email protected]</td> 
      <td>(21) 9999-8888</td> 
     </tr> 
     <tr> 
      <td>002</td> 
      <td>Maria Silva</td> 
      <td>[email protected]</td> 
      <td>(81) 8787-8686</td> 
     </tr> 
     <tr> 
      <td>003</td> 
      <td>José Pedro</td> 
      <td>[email protected]</td> 
      <td>(84) 3232-3232</td> 
     </tr> 
    </tbody> 
</table> 

CSS

* { 
    font-family: Consolas; 
} 

.editableTable { 
    border: solid 1px; 
    width: 100% 
} 

.editableTable td { 
    border: solid 1px; 
} 

.editableTable .editingCell { 
    padding: 0; 
} 

.editableTable .editingCell input[type=text] { 
    width: 100%; 
    border: 0; 
    background-color: rgb(255,253,210); 
} 

JS

$(function() { 

    $("td").dblclick(function() { 
     var originalContent = $(this).text(); 

     $(this).addClass("editingCell"); 
     $(this).html("<input type='text' value='" + originalContent + "' />"); 
     $(this).children().first().focus(); 

     $(this).children().first().keypress(function (e) { 
      if (e.which == 13) { 
       var newContent = $(this).val(); 
       $(this).parent().text(newContent); 
       $(this).parent().removeClass("editingCell"); 
      } 
     }); 

     $(this).children().first().blur(function(){ 
      $(this).parent().text(originalContent); 
      $(this).parent().removeClass("editingCell"); 
     }); 
    }); 

});