-1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<script language="JavaScript" type="text/javascript"> 
  function mail_login(url) { 
    alert(url);
    var form=getElementById('autologin');
    var input1=document.createElement('input');
    input1.id='autologin_name';
    input1.type='text';
    input1.name='Username';
    form.appendChild(input1);

    var input2=document.createElement('input');
    input2.id='autologin_password';
    input2.type='text';
    input2.name='Password';
    form.appendChild(input2);
    document.getElementById('autologin').action=url;
    document.forms[0].username.value = 'xxx'; 
    document.forms[0].password.value = 'xxx'; 
    document.forms[0].submit(); 
  }

</script> 
</head> 
<body> 
<form id='autologin' method="post" target='_blank'> 

<a href='javascript:void(0);' onclick="mail_login('https://inchnm02.tcs.com/names.nsf?Login');" >click here to login to your tcs mail</a><br>
</form> 
</body> 
</html>

如果我将元素直接放在表单中,那么它可以正常工作。如下所示。

<input type="text" name="Username" /> 
<input type="text" name="Password" /> 
4

1 回答 1

2
var form=getElementById('autologin');

我相信它是 document.getElementById

于 2013-09-24T17:12:54.717 回答