- html中<select>标签用法解析及如何设置select的默认选中状态
< 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伪类,用于设置鼠标悬停样式的改变
.ui-dialog-closeButton{
background: url(img/close0.png);
}
.ui-dialog-closeButton:hover{
/*hover伪类,用于设置鼠标悬停样式的改变*/
background: url(img/close1.png);
}