moller
小狐狸
小狐狸
  • UID22671
  • 注册日期2008-01-17
  • 最后登录2008-01-17
  • 发帖数1
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:7937回复:3

请教一个老问题,为什么我的代码在IE下可以,在Firefox下不行。

楼主#
更多 发布于:2008-01-17 22:32
在IE下面,input的值是自动写上的。而在Firefox下,就有个错误,不能显示。代码如下,请高手指点,多谢先。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title></title>

<script type="text/javascript">
function insertHtml(where, el, html){
        where = where.toLowerCase();
        if(el.insertAdjacentHTML){
            switch(where){
                case "beforebegin":
                    el.insertAdjacentHTML('BeforeBegin', html);
                    return el.previousSibling;
                case "afterbegin":
                    el.insertAdjacentHTML('AfterBegin', html);
                    return el.firstChild;
                case "beforeend":
                    el.insertAdjacentHTML('BeforeEnd', html);
                    return el.lastChild;
                case "afterend":
                    el.insertAdjacentHTML('AfterEnd', html);
                    return el.nextSibling;
            }
            throw 'Illegal insertion point -> "' + where + '"';
        }
  var range = el.ownerDocument.createRange();
        var frag;
        switch(where){
             case "beforebegin":
                range.setStartBefore(el);
                frag = range.createContextualFragment(html);
                el.parentNode.insertBefore(frag, el);
                return el.previousSibling;
             case "afterbegin":
                if(el.firstChild){
                    range.setStartBefore(el.firstChild);
                    frag = range.createContextualFragment(html);
                    el.insertBefore(frag, el.firstChild);
                    return el.firstChild;
                }else{
                    el.innerHTML = html;
                    return el.firstChild;
                }
            case "beforeend":
                if(el.lastChild){
                    range.setStartAfter(el.lastChild);
                    frag = range.createContextualFragment(html);
                    el.appendChild(frag);
                    return el.lastChild;
                }else{
                    el.innerHTML = html;
                    return el.lastChild;
                }
            case "afterend":
                range.setStartAfter(el);
                frag = range.createContextualFragment(html);
                el.parentNode.insertBefore(frag, el.nextSibling);
                return el.nextSibling;
            }
            throw 'Illegal insertion point -> "' + where + '"';
    }
</script>
<script type="text/javascript">
	var mydivAddContactButton;
	var myHtmlString;
	function Main()
	{		
		mydivAddContactButton =  document.getElementById("divAddContactButton");
		if(2 == 0)
		{
			// add a single contact to show the user where to start
			AddContact();
		}
		else
		{
			ShowOldContacts();
		}	
	    
	}
	function ShowOldContacts()
	{

		AddContactWithValues("Account","Tom","1039717","tom.lee@hotmail.com");
		AddContactWithValues("CEO","","","moller@yahoo.com");
		GetContactsNo();
	}
	
	function AddContact()
	{
		if(myHtmlString!="")
		{
			myHtmlString =  document.getElementById("HiddenContactRow").innerHTML;

		}
		insertHtml("beforeBegin", mydivAddContactButton, myHtmlString);
		//mydivAddContactButton.scrollIntoView(false);
		
		var aContactObjects = document.getElementsByName("ContactObject");
		var iContactCount = aContactObjects.length -1;
		var aContactIdObjects = document.getElementsByName("ContactId");
		var aRoleIdObjects = document.getElementsByName("RoleId");
		var aNameIdObjects = document.getElementsByName("NameId");
		var aPhoneIdObjects = document.getElementsByName("PhoneId");
		var aEmailIdObjects = document.getElementsByName("EmailId");
		var iContactIdObjects = aContactIdObjects.length -1;

		aContactIdObjects.item(iContactIdObjects).name = "ContactId"+iContactCount;
		//aContactIdObjects.item(iContactIdObjects).value = "ContactId"+iContactCount;
		//document.getElementById("ContactCount").value = "ContactId"+iContactCount;

		aRoleIdObjects.item(iContactIdObjects).name = "RoleId"+iContactCount;
		aNameIdObjects.item(iContactIdObjects).name = "NameId"+iContactCount;
		aPhoneIdObjects.item(iContactIdObjects).name = "PhoneId"+iContactCount;
		aEmailIdObjects.item(iContactIdObjects).name = "EmailId"+iContactCount;

		GetContactsNo();

	}

	function AddContactWithValues(sTitle, sName, sPhone, sEmail)
	{
		if(myHtmlString!="")
		{
			myHtmlString =  document.getElementById("HiddenContactRow").innerHTML;

		}
		insertHtml("beforeBegin", mydivAddContactButton, myHtmlString);
		//mydivAddContactButton.scrollIntoView(false);
		
		var aContactObjects = document.getElementsByName("ContactObject");
		var iContactCount = aContactObjects.length -1;
		
		var aContactIdObjects = document.getElementsByName("ContactId");
		var aRoleIdObjects = document.getElementsByName("RoleId");

		var aNameIdObjects = document.getElementsByName("NameId");
		var aPhoneIdObjects = document.getElementsByName("PhoneId");
		var aEmailIdObjects = document.getElementsByName("EmailId");
		var iContactIdObjects = aContactIdObjects.length -1;
		

		aContactIdObjects.item(iContactIdObjects).name = "ContactId"+iContactCount;

		aRoleIdObjects.item(iContactIdObjects).name = "RoleId"+iContactCount;
		aNameIdObjects.item(iContactIdObjects).name = "NameId"+iContactCount;
		aPhoneIdObjects.item(iContactIdObjects).name = "PhoneId"+iContactCount;
		aEmailIdObjects.item(iContactIdObjects).name = "EmailId"+iContactCount;

		aRoleIdObjects.item(iContactIdObjects).value = sTitle;
		aNameIdObjects.item(iContactIdObjects).value = sName;
		aPhoneIdObjects.item(iContactIdObjects).value = sPhone;
		aEmailIdObjects.item(iContactIdObjects).value = sEmail;
	}
	
</script>

</head>

<body onLoad="javascript:Main()">

<form action="abc.php" method="post" onSubmit="javascript:return Submit()">

<span id="HiddenContactRow" style="display: none">
	<span class="ContactObject" name="ContactObject" id="ContactObject">
		<table border="0" cellpadding="0" cellspacing="0" width="720">
			<tr>
				<td width="59"><input name="ContactId" id="ContactId" type="text" value=""  size="2" /></td>
				<td width="102"><input name="RoleId" id="RoleId" type="text" value="" maxlength="20" size="20" /></td>
				<td width="113"><input name="NameId" id="NameId" type="text" value="" maxlength="100" size="20" /></td>
				<td width="151"><input name="PhoneId" id="PhoneId" type="text" value=""  maxlength="20" size="20" /></td>

				<td width="232"><input name="EmailId" id="EmailId" type="text" value="" maxlength="100" size="20" /></td>
				<td width="37"><img src="images/DelIcon.png" width="16" height="16" onClick="Delete(this)" alt="Delete contact"></td>
			</tr>
		</table>
	</span>
</span>


  <table width="720"  border="0">
  <tr align="left">

      <th width="59">Number:</th>
      <th width="102">Role:</th>
      <th width="113">Name:</th>
      <th width="151">Phone Number:</th>
      <th width="232">Email:</th>
      <th width="37" style="display: none" >Del</th>

  </tr>
  </table>
  <div id="ContactRows">  
  </div>
 
  <p>
	 <div align="right" id="divAddContactButton">
	 	<input type="button" id="AddContactButton" value="Add Contact" class="inpAddContact" onClick="AddContact()"/>
	 </div>

  </p>

  <p>
    <input type="hidden" name="ContactCount" id="ContactCount" value=""/> 
    <input type="submit" id="SubmitButton" name="SubmitButton" value="Submit"/>
  </p>
</form>

</body>
</html>
游客

返回顶部