0

ランダムなパスワード(このコードは完全に実行されています)を生成しようとしています。このパスワードは[パスワード]テキストボックスの値に貼り付けられますが、javascript関数の呼び出し中に問題が発生します。

これが私のJavaScriptです:

function password() {
    var chars =   "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    var table = document.getElementById('table'),
    rows = table.getElementsByTagName('tr'),
    i,j, cells, password;
    for (var i=0; i<string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum,rnum+1);
    }
    for (i=0,j = rows.length; i<j;++i)
    {
    cells = rows[i].getElementsById('td');
    if(!cells.length)
    {continue;
    }
    password = cells[j].innerText;
    alert("hi "+password);
    }
    alert("Password is : "+randomstring);
    document.f2.password.value = randomstring;
}

これが私のテーブルです:

<table name="table" id="table" cellpadding="4" cellspacing="2" border="1" bgcolor="" >
<tr name="tr" id="tr">
<th><input type="checkbox" name="allCheck" onclick="selectallMe()"></th>
<th>Emp ID</th>
<th>Device</th>
<th>Feature Status</th>
<th>Policy</th>
<th>Password Management</th>
</tr>
<tr>
<%  while(rs.next()){ %>
<td><input type="checkbox" name="chkName" onclick="selectall()"></td> 
<td><input type="text"  name="empId" value="<%= rs.getString(1)%> "   disabled="disabled"  maxlength="10"></td>
<td><input type="text" name="device" value="<%= rs.getString(2)%>"   disabled="disabled" maxlength="10"></td>
<td><input type="text"  name="features" value="<%= rs.getString(3)%>"  disabled="disabled" maxlength="60"></td>
<td><input type="text"  name="policyName" value="<%= rs.getString(4)%>"  disabled="disabled" maxlength="10"></td>
<td id="td" name="td"><input type="text" name="password" id="password" value=""  ><input type="button" name="Password" value="Password" onclick="password()"><input type="reset"  name="Reset" value="Rseset"></td>
</tr>
<% } 
%>
</table>

私のJSでは何が問題になっていますか?[パスワード]列を繰り返し処理したいのでPassword()、[パスワード]セルに値を割り当てます。

4

1 に答える 1

0

これをコメントに入れたいのですが、まだ評判がありません。

まず、セルをテキスト入力タイプにしたい特定の理由はありますか? 作成時にそれらを無効にしているだけなので。rows[index].cells(); も調べてください。および table.rows(); JS のメソッド。これらは、セルと行の配列を提供します。そこから、必要な場所まで反復できます。詳細については、 http://www.javascriptkit.com/domref/tableproperties.shtml をご覧ください。

それが役に立てば幸い

于 2012-05-17T13:23:05.723 に答える