var radios=document.getElementsByName("workMode");
var workMode="";
for(var i=0;i<radios.length;i++){
if(radios[i].checked==true){
workMode=radios[i].value;
}
}
11.向select中动态添加option
复制代码 代码如下:
<select onchange="cityResult()">
var prov=document.getElementById("ddlProvince");
prov.options.add(new Option("---请选择---",""));
var pArray=zoneIdProvince.split("&");
for(var i=0;i<pArray.length;i++){
var idpArray=pArray[i].split("#");
var sZoneID=idpArray[0];
var sProvince=idpArray[1];
prov.options.add(new Option(sProvince,sZoneID));
}
12.页面中使用prototype ajax提交数据的实现方式(java)
一步:在<head></head>中添加以下js文件链接
复制代码 代码如下:
<head>
<script language="JavaScript" src="https://www.jb51.net/NDHotel/js/prototype-1.6.js"></script>
</head>
二步:把prototype-1.6.js文件放到/NDHotel/js/指定的目录中
三步:在<script type="text/javascript"></script>中声明以下调用函数
复制代码 代码如下:
<script type="text/javascript">
function editIpSegment(){
var url='/NDHotel/ipsegmentset.do?method=roomChangeNotice';
var pars = 'startip='+startip+'&endip='+endip+'&lindex='+lindex;
new Ajax.Request( url, {method: 'get', parameters: pars, asynchronous:false,onComplete:editResult});
}
function editResult(result){
var returnStr = result.responseText;
if(returnStr =='fail'){
alert("");
return false;
}
}
</script>
四步:实现后台调用
复制代码 代码如下:
public ActionForward roomChangeNotice(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String result = "";
PrintWriter pw = RainPrintWriter.getPrintWriter(response);
try {
NotifyServiceTwo.sendMessage(4, 0);
result = "success";
} catch (Exception e) {
logger.error("roomChangeNotice" + e);
}
pw.write(result);
pw.close();
return null;
}
13.js中获取表单的值的方式:
复制代码 代码如下:
document.getElementById("lindex").value
document.all.lindex.value//lindex在页面中必须是唯一的
//设置获取焦点
document.getElementById("lindex").focus()
document.all.startip.focus()
//设置失去焦点
document.getElementById("lindex").blur()
document.all.startip.blur()
14.动态添加/删除表格中的行
复制代码 代码如下:
<table cellpadding="0" cellspacing="0">
</table>
//动态生成table的行
var autoId = 0; // 自增变量
function addRow(value1,value2){
var highQuery=document.getElementById("tdSearch");
highQuery.insertRow();
var newRow = highQuery.rows[highQuery.rows.length - 1];
newRow.id = "row_" + autoId;
newRow.insertCell();
newRow.cells[0].innerHTML = "<input value='"+value1+"' onchange='changeip("+autoId+")' type='text'>-";
newRow.insertCell();
newRow.cells[1].innerHTML = "<input value='"+value2+"' type='text'> ";
var cell2 = newRow.insertCell();
cell2.innerHTML = "<input type='button' value='-' onClick=removeRow('" + newRow.id + "')>";
cell2.setAttribute("class", "yellowCell2");
autoId=autoId+1;
}
function removeRow(rowId){
var trRow = document.getElementById(rowId);
//alert(trRow);
//if(rowId!="row_0"){
trRow.removeNode(true);
//}
}
15. 集合
复制代码 代码如下: