我想要 javascript 中的一个函数,它可以在单击按钮时将光标更改为 png 图像。这是我一直在 html 和 javascript 中使用的代码,但显然它不起作用,有人可以帮助我吗?
<form>
<input type="button"
onclick="changeCursor()"
value="click here"
/>
</form>
...
function changeCursor() {
cursor.style = "myImage.png"
}
最佳答案
单击按钮时添加 cursor
属性。
var btn = document.getElementById('btn');
btn.addEventListener('click', function() {
document.body.style.cursor = 'url(http://dummyimage.com/40x40/000/fff), auto';
})
html, body {
width: 100%;
height: 100%;
background-color: coral;
margin: 0 auto;
}
<input id="btn" type="button" value="click here" />
关于javascript - 试图在 javascript 中更改光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27368655/