<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
window.onload = function() {
function insertRow(){
alert("ok");
var rowIndex1 = document.all("addordel").length;
if(rowIndex1 >= 5){
alert('一次最多能上传5个文件');
return false;
}
var obj=document.getElementsByName("addordel")[0].cloneNode(true);
document.all("change").appendChild(obj);
}
function delRow(){
var rowIndex = document.all("addordel").length;
if(rowIndex >= 2){
event.srcElement.parentNode.removeNode(true);
}
}
function chkfile(){
alert("okok");
obj = document.getElementsByName('upname[]');
num = obj.length;
for(i=0;i<num;i++){
if(obj[i].value == 0){
alert('请添加上传文件');
return false;
}
}
}
}
</script>
</head>
<body>
<div style=" background-image:url(images/upfile.gif); background-position:left; background-repeat:no-repeat; width: 95%; height:43px;"> </div>
<hr style=" width: 95%; border:1px #597ecf solid;" />
<div style=" width: 95%; height:25px; background-color: #FFFFCC; border: 1px #FFFF66; line-height: 25px; text-align:center; color:#ff0000;"> 上传文件限制:100M</div>
<form method="post" enctype="multipart/form-data" action="?act=upfile">
<ul id="change">
<li id="addordel" ><input id="upname[]" name="upname[]" type="file" style=" width: 200px; background-color:#f0f0f0; " />
<select id="foundtype[]" name="foundtype[]">
<?php
$typesql = "select genrename from tb_uptype";
$typearr = $conne->getRowsArray($typesql);
$conne->close_rst();
foreach($typearr as $value){
?>
<option value="<?php echo $value['genrename']; ?>"><?php echo $value['genrename']; ?></option>
<?php
}
?>
</select>
<select id="ispub[]" name="ispub[]">
<option value="0" selected="selected">不公开</option>
<option value="1">公开</option>
</select>
<button onClick="delRow()" style=" border: 1px #CCCCCC solid; background-color:#f0f0f0;">删除</button> <button onClick="insertRow()" style=" border: 1px #cccccc solid; background-color: #f0f0f0;">增加</button> </li>
</ul>
<input id="upbtn" name="upbtn" type="submit" value="上传" onClick="return chkfile()" style=" background-color:#f0f0f0; border: 1px #CCCCCC solid;" />
</form>
</body>
</html>
请问:
怎么无法触发onCick事件。
//window.onload = function() { //去掉
function insertRow(){
alert("ok");
var rowIndex1 = document.all("addordel").length;
if(rowIndex1 >= 5){
alert('一次最多能上传5个文件');
return false;
}
var obj=document.getElementsByName("addordel")[0].cloneNode(true);
document.all("change").appendChild(obj);
}
function delRow(){
alert("fff");
var rowIndex = document.all("addordel").length;
if(rowIndex >= 2){
event.srcElement.parentNode.removeNode(true);
}
}
function chkfile(){
alert("okok");
obj = document.getElementsByName('upname[]');
num = obj.length;
for(i=0;i<num;i++){
if(obj[i].value == 0){
alert('请添加上传文件');
return false;
}
}
}
//}//去掉
你可以改为
把type改为button
然后点击事件中用ajax方式提交表单
2:要么,在window.onload = function() {
//在这里直接绑定事件,比如你最后的上传事件绑定
document.getElementById("upbtn").onclick=chkfile;
}