js set Cursor style.

本文介绍了一种使用JavaScript来动态更改HTML元素光标样式的实现方法。通过定义一个名为setCursorByID的函数,可以根据传入的ID选择指定的HTML元素,并修改其cursor属性,从而改变鼠标在其上的显示样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.javascripter.net/faq/stylesc.htm

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script language="JavaScript">

	function setCursorByID(id, cursorStyle) {
		var elem;
		if (document.getElementById && (elem = document.getElementById(id))) {
			if (elem.style)
				elem.style.cursor = cursorStyle;
		}
	}

</script>
</head>
<body>
	<span style="cursor: auto;">auto</span>
	<span style="cursor: move;">move</span>
	<span style="cursor: no-drop;">no-drop</span>
	<span style="cursor: col-resize;">col-resize</span>
	<span style="cursor: all-scroll;">all-scroll</span>
	<span style="cursor: pointer;">pointer</span>
	<span style="cursor: not-allowed;">not-allowed</span>
	<span style="cursor: row-resize;">row-resize</span>
	<span style="cursor: crosshair;">crosshair</span>
	<span style="cursor: progress;">progress</span>
	<span style="cursor: e-resize;">e-resize</span>
	<span style="cursor: ne-resize;">ne-resize</span>
	<span style="cursor: default;">default</span>
	<span style="cursor: text;">text</span>
	<span style="cursor: n-resize;">n-resize</span>
	<span style="cursor: nw-resize;">nw-resize</span>
	<span style="cursor: help;">help</span>
	<span style="cursor: vertical-text;">vertical-text</span>
	<span style="cursor: s-resize;">s-resize</span>
	<span style="cursor: se-resize;">se-resize</span>
	<span style="cursor: inherit;">inherit</span>
	<span style="cursor: wait;">wait</span>
	<span style="cursor: w-resize;">w-resize</span>
	<span style="cursor: sw-resize;">sw-resize</span>
	<div>
		<a id="e1h" href="#" style="cursor: help;" onclick="setCursorByID('e1','help');return false;">help</a> 
		<a id="e1w" href="#" style="cursor: wait;" onclick="setCursorByID('e1','wait');return false;">wait</a>
		<a id="e1m" href="#" style="cursor: move;" onclick="setCursorByID('e1','move');return false;">move</a> 
		<a id="e1c" href="#" style="cursor: crosshair;" onclick="setCursorByID('e1','crosshair');return false;">crosshair</a>
		<a id="e1t" href="#" style="cursor: text;" onclick="setCursorByID('e1','text');return false;">text</a> 
		<a id="e1a" href="#" style="cursor: default;" onclick="setCursorByID('e1','default');return false;">default</a> 
		<a id="e1a" href="#" style="cursor: pointer;" onclick="setCursorByID('e1','pointer');return false;">pointer</a> 
		<a id="e1a" href="#" style="cursor: auto;" onclick="setCursorByID('e1','auto');return false;">auto</a>
	</div>
	<div>
		<a id="e1" href="#" onclick="setCursorByID('e1','help');return false;">test</a> 
	</div>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值