当我尝试运行以下代码时,我一直收到错误:
无法在"id“处设置null的属性"value”
我曾尝试将属性从value
更改为innerHTML
,但这不起作用。如果你能帮助我,我将不胜感激。谢谢!
<div class="input-field s6 col" style="color: white; background-color:transparent;">
<input id="avatar_url" id="ipoza" type="text" onfocus="style='background-color:white;'" onblur="style='background-color:transparent'" value="http://i01.c.aliimg.com/img/ibank/2014/101/288/1614882101_2028072840.jpg"> <label for="avatar_url"><p>Poza de Profil</p></label>
</div>
<button onclick="i()"></button>
<script type="text/javascript">
function i() {
document.getElementById("ipoza").value = "Link";
}
</script>
发布于 2018-07-15 07:54:00
每个元素只能有一个id
。您的input
有%2个id
%s,这是不允许的。只需给它一个ipoza
的id
,这样你就可以用document.getElementById("ipoza")
选择它了。
<div class="input-field s6 col" style="color: white; background-color:transparent;">
<input id="ipoza" type="text" onfocus="style='background-color:white;'" onblur="style='background-color:transparent'" value="http://i01.c.aliimg.com/img/ibank/2014/101/288/1614882101_2028072840.jpg"> <label for="ipoza"><p>Poza de Profil</p></label>
</div>
<button onclick="i()"></button>
<script type="text/javascript">
function i() {
document.getElementById("ipoza").value = "Link";
}
</script>
https://stackoverflow.com/questions/51344195
复制相似问题