- html中<select>標簽用法解析及如何設(shè)置select的默認選中狀態(tài)
< script type = "text/javascript" >
function change(){
document.getElementById("sel")[2].selected=true;
}
</ script >
< select id = "sel" >
< option value = "1" >1</ option >
< option value = "2" >2</ option >
< option value = "3" >3</ option >
</ select >
< input type = "button" value = "修改" onclick = "change()" />```
獲取<select>標簽選中項文本的js代碼為:
```swift
var val = document.all.Item.options[document.all.Item.selectedIndex].text;
var i=document.getElementById('sel').options[document.getElementById('sel').selectedIndex].value;```
- 如何增加和刪除一行
```swift
<input type="button" value="增加" id="addTable"/>
<input type="button" value="刪除" id="deleteTable"/>
<table id="table1"></table>
<script type="text/javascript" src="jquery-3.1.0.min.js"></script>
<script>
$(document).ready(function(){
$("#addTable").click(function(){
var tr="<tr><td><input type=\"checkbox\" name=\"check\"/>"+
"</td><td>111</td><td>222</td><td>333</td></tr>";
$("#table1").append(tr);
});
$("#deleteTable").click(function(){
var check = document.getElementsByName("check");
for(var i=0;i<check.length;i++){
if(check[i].checked){
document.getElementById('table1').deleteRow(i);
i--;
}
}
})
})
</script>
hover偽類奉芦,用于設(shè)置鼠標懸停樣式的改變
.ui-dialog-closeButton{
background: url(img/close0.png);
}
.ui-dialog-closeButton:hover{
/*hover偽類,用于設(shè)置鼠標懸停樣式的改變*/
background: url(img/close1.png);
}