JavaScript 实现动态增加、删除表单域四例
|
admin
2011年3月11日 22:49
本文热度 6118
|
例一:
[code]
New Document
<script LANGUAGE="JavaScript">
</script>
[/code]
例二:
[code]
Untitled Document
<script language="VBScript">
NowFileInputNo = 1
NowFileInputCount = 0
Sub AddFileInput()
If NowFileInputCount < 10 Then
HTMLSrc = "
"& vbcrlf
document.all.add_line.InsertAdjacentHTML "beforeBegin", HTMLSrc
NowFileInputNo = NowFileInputNo + 1
NowFileInputCount = NowFileInputCount + 1
Else
Alert "增加太多记录行"
End IF
End Sub
Sub DelFileInput(tableno)
document.all("FileInput"& tableno).outerHTML = ""
NowFileInputCount = NowFileInputCount - 1
End Sub
</script>
[/code]
例三:
[code]
<script>
function addNewQuestion()
{
document.form1.newTable.value = parseInt(document.form1.newTable.value) + 1;
var newItemId;
if( (document.form1.newTable.value).length > 2 )
{
alert("您的调查问题总数不能超过 99 个。")
window.location.reload();
}
newItemId = document.form1.newTable.value;
var objItem = '
';
document.all.__idInsertBefore.insertAdjacentHTML("beforeBegin", objItem);
}
function showTips(obj)
{
obj.title=obj.value;
}
function addNewChild(obj)
{
var isblank = "false";
var objName = obj.name;
var last2Char = objName.substring(objName.length - 2);
if( last2Char.substring(0, 1) > '9' || last2Char.substring(0, 1) < '0' )
{
last2Char = last2Char.substring(1, 2);
}
for(var i=0; i < document.form1.elements[objName].length; i++)
{
if(document.form1.elements[objName].item(i).value == "")
isblank = "yes"
}
if( isblank != "yes" )
{
var objItem = '
问题选项:';
objItem += ' ';
objItem += '
';
objName = "__idQueOption" + last2Char;
var varQueOption = document.all[objName];
if( varQueOption.length != null )
varQueOption = varQueOption.item(varQueOption.length-1);
varQueOption.insertAdjacentHTML("afterEnd",objItem);
}
}
</script>
[/code]
例四:
[code]
Untitled Document
<script language="JavaScript">
function form_submit()
{
var nn=document.form1.file_num.value;
alert("Total:"+nn);
}
</script>
<script language="JavaScript">
var n=1;
</script>
[/code]
该文章在 2011/3/11 22:49:35 编辑过