我有一些文本表單元素我想作爲div的樣式只有佔位符文本可見,除非點擊,然後添加CSS類,使其看起來和行爲像一個文本框一旦點擊。css刪除文本輸入樣式
什麼CSS我需要添加到.subtask-hide
,使它看起來像一個空白的div,直到我點擊一次?
<style>
.subtask {
display: block;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
.subtask-cancel{
line-height: 34px;
}
.subtask-cancel-hide {
display: none;
}
.subtask-hide {
}
</style>
<div class="form-group col-xs-12">
<div class="col-xs-12">
<div class="col-xs-1"></div>
<input type="text" id="AddNewSubTask" name="AddNewSubTask" placeholder="Add New SubTask" class="subtask-hide col-xs-10" onclick="allowInput(this);">
<div id="cancelTask" class="fa fa-times fa-2x col-xs-1 subtask-cancel-hide" aria-hidden="true" onclick="disallowInput(this);"></div>
</div>
</div>
<script>
function allowInput(el){
console.log(el);
// will remove .subtask-hide and add .subtask to element clicked
// will remove .subtask-cancel-hide and add .subtask-cancel to second element of parent when clicked
}
function disallowInput(el){
console.log(el);
// will remove value and .subtask of element and add .subtask-hide when clicked
// will remove .subtask-cancel and add .subtask-cancel-hide to second element of parent when clicked
}
<script>
你是想只顯示''''的'文本'placeholder'點擊placeholder'直到? – guest271314
這看起來不像是向我寫JavaScript的嘗試,但是你會想改變'Element.style'屬性值,比如'Element.style.background ='#000;''或者其他東西。順便說一下,這只是一個不好的例子。確保在更改樣式時設置了'Element.readOnly = true;'或'Element.readOnly = false;'如果您希望或不希望用戶能夠進行交互,請更改樣式。 – PHPglue