设置<input type="text">的默认值

转载:http://iamzhangxiaochuan.blog.163.com/blog/static/1818142802011225101621401/

设置<input type="text">的默认值最基本的就是用value设置默认值,例如<input type="text" value="默认值">。但是如果想让默认值在鼠标点击的时候消失,那么就要用js去实现动态的效果,例如<input name="textfield" type="text" value="默认值" οnfοcus="if (value =='默认值){value =''}" οnblur="if (value ==''){value='默认值}" /> 。当鼠标移动到文本框的时候,触发onfocus,如果value的值为默认值,则清空文本框。当鼠标移出文本框的时候,触发onblur,如果value的值为空,则设置文本框的默认值为“默认值”。

示例:

<tr>
<th><wicket:message key="fibu.projektPersonalCost" /></th>
<td>
<table>
<tr>
<td>人员</td>
<td><input type="text" value="Cost"
onfocus="if(value=='Cost'){value=''}"
onblur="if(value==''){value='Cost'}"/>
</td>
<td><input type="text" value="Bill"
onfocus="if(value=='Bill'){value=''}"
onblur="if(value==''){value='Bill'}"/>
</td>
<td>累计时间</td>
</tr>
</table>
</td>
</tr>
<tr> <td contenteditable="true"><input type="text" oninput="filterTable(0)" placeholder="工艺膜层"></td> <td contenteditable="true"><input type="text" oninput="filterTable(1)" placeholder="AOI Step"></td> <td contenteditable="true"><input type="text" oninput="filterTable(2)" placeholder="不良类型"></td> <td contenteditable="true"><input type="text" oninput="filterTable(3)" placeholder="Layer(Code)"></td> <td contenteditable="true"><input type="text" oninput="filterTable(4)" placeholder="Type"></td> <td contenteditable="true"><input type="text" oninput="filterTable(5)" placeholder="Dpet"></td> <td contenteditable="true"><input type="text" oninput="filterTable(6)" placeholder="Subcode"></td> <td contenteditable="true">Code描述</td> <td contenteditable="true">Image1</td> <td contenteditable="true">Image2</td> <td contenteditable="true">Image3</td> <td contenteditable="true">Image4</td> <td contenteditable="true">Image5</td> <td contenteditable="true">Image6</td> <td contenteditable="true">判定细则</td> </tr>var table = document.getElementById("myTable"); var imageColumnIndices = [8, 9, 10,11,12,13]; // 指定要添加图片按钮的列索引数组 function addRow() { var newRow = table.insertRow(); var cellsCount = table.rows[0].cells.length; for (var i = 0; i < cellsCount; i++) { var newCell = newRow.insertCell(); newCell.contentEditable = true; if (imageColumnIndices.includes(i)) { var newInput = document.createElement("input"); newInput.type = "file"; newInput.onchange = function() { previewImage(this); }; newInput.onclick = function() { showPopup(this.src); }; newCell.appendChild(newInput); }else { newCell.innerHTML = "新单元格"; // 将空余按钮的单元格内容设置默认值 } } } function addColumn() { var cellsCount = table.rows[0].cells.length; for (var i = 0; i < table.rows.length; i++) { var newCell = table.rows[i].insertCell(); newCell.contentEditable = true; newCell.innerHTML = "新单元格"; } } function deleteRow() { if (table.rows.length > 2) { table.deleteRow(table.rows.length - 1); } } function deleteColumn() { if (table.rows[0].cells.length > 1) { for (var i = 0; i < table.rows.length; i++) { table.rows[i].deleteCell(table.rows[i].cells.length - 1); } } }我需要指定某列宽度,需要怎么处理
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值