我的包含page.php
默认类型为:div id="container"
id="input"
input type="text"
<div class="container">
<div class="row">
<div class="col-75">
<div id="container">
<input type="text" id="input" value="" name="password">
</div>
<input type="submit" value="OK" id="logBtn">
</div>
</div>
</div>
我想更改input type="text"
为与接收值input type="password"
相同的输入:id="input"
textToPassType(1)
function textToPassType(val1){
if (val1 == 1){
document.getElementById('input').type = 'password';
} else if (val1 == 0){
document.getElementById('input').type = 'text';
}
}
这种方法只有在我调用这个函数时才有效page.php
,但是如果在外部文档中使用它:<script type="text/javascript" src="myjs.js"></script>
方法不起作用。所以,我正在寻找一些正确的方法来动态更改输入类型并从外部保持相同的 id 名称myjs.js
到我的page.php