JSFiddle - React, Tailwind, and code Playground
HTML
<form class="login" action="foo">
<input id="username" type="text" placeholder="ユーザー名" />
<input id="password2" type="password" placeholder="パスワード"/>
<input id="submit" type="submit" value="ログイン" />
<br />ttt
<input id="show-ps" type="checkbox" /><label for="show-ps">パスワードを表示</label>
</form>
JavaScript
function changeInputType(inputId, type) {
var input = $("#" + inputId);
$(input).replaceWith($("<input />").val(input.val()).attr("placeholder", input.attr("placeholder")).attr("id", inputId).attr("type", type));
}
$("#show-ps").change(function() {
if ($(this).attr("checked")) {
changeInputType("password2", "text");
} else {
changeInputType("password2", "password");
}
});
if ($("#show-ps").attr("checked")) {
changeInputType("password2", "text");
}