良い一日。このコードを使用して、ある入力から別の入力に値を複製します。
<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);
ありがとうございました。