0

良い一日。このコードを使用して、ある入力から別の入力に値を複製します。

<script type = "text/javascript">
function transfer(which) {
document.getElementById("temp_name").value = which;
}
</script>
<form action="register.php" method="post" name="register">
<input type="text" name="username" id = "username" onkeyup = "transfer(this.value)"><br>
<input type="text" name="temp_name" id = "temp_name">
</form>

これは #username を #temp_name に複製しますが、余分なハイフンと小文字を使用せずにテキスト #temp_name を追加する必要があります。したがって、このコードを上位コードに追加する必要があります。

.replace(/\s/g,'-'); // to replace spaces with hypens
tmp_str = tmp_str.replace(/[\-]+/g,'-');    // to remove extra hypens
tmp_str = tmp_str.replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase(); // to convert to lower case and only allow alpabets and number and hypehn
tmp_str = alltrimhyphen(tmp_str);

ありがとうございました。

4

1 に答える 1

1

tmp_str簡単な解決策、次のように置き換えるだけwhichです:

<script type="text/javascript">
    function transfer(which) {
        which = which.replace(/\s/g,'-'); // to replace spaces with hypens
        which = which.replace(/[\-]+/g,'-');    // to remove extra hypens
        which = which.replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase(); // to convert to lower case 
        document.getElementById("temp_name").value = which;
   }
</script>

<form action="register.php" method="post" name="register">
    <input type="text" name="username" id="username" onkeyup="javascript:transfer(this.value);">
    <br />
    <input type="text" name="temp_name" id="temp_name">
</form>
于 2012-09-17T14:58:48.777 に答える