1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <header>password</header>
- <body>
- <script>
- function Password(parent, open) {
- this.input = document.createElement("input");
- parent.append(this.input);
- //this.input.type = open ? "text" : "password";
- this.setValue = function (value) {
- this.input.value = value;
- }
- this.getValue = function () {
- return this.input.value;
- }
- this.setOpen = function (open) {
- this.input.type = open ? "text" : "password";
- }
- this.getOpen = function () {
- return this.input.type == "text";
- }
- this.input.onchange = function () {
- if (this.onChange)
- this.onChange(this.getValue());
- }.bind(this);
- let check = document.createElement("input");
- parent.append(check);
- check.onchange = function () {
- this.setOpen(check.checked);
- if (this.onOpenChange)
- this.onOpenChange(this.getOpen());
- }.bind(this);
- check.checked = open;
- check.value = "open";
- check.type = "checkbox";
- }
- let p = new Password(document.body, true);
- p.onChange = data => console.log(data)
- p.onOpenChange = open => console.log(open)
- p.setValue('qwerty')
- console.log(p.getValue())
- p.setOpen(false)
- console.log(p.getOpen())
- </script>
- </body>
|