【问题标题】:What is the best way to change the cursor in JQuery在 JQuery 中更改光标的最佳方法是什么
【发布时间】:2010-07-08 19:30:04
【问题描述】:

我是 JQuery 的新手。
我正在尝试在我的 HTML 网页中添加一些代码来更改光标,
但我不确定这是否是单独使用 JQuery 而不是在外部 CSS 中进行一些自定义声明的最佳方法。
(不知道 JQuery 有没有内置的 CSS 属性。)

这是我非常简单的 HTML 网页的代码:

<script type="text/javascript">
 $(document).ready(function(){
  $("#replybox").draggable();         
         $("#closed").mouseover(function(){
         $("#closed").css("cursor","pointer"); 
         });        
 });
</script>
<div id="replybox">
<form>
<table border="2">
<tr><td align="center" bgcolor="#FFAAAA">
<span id="closed">Press here to close this box</span></td></tr>
<tr>
<td align="center">
Content:<textarea name="data[Reply][quote]" id="data[Reply][quote]" cols="72" rows="18">Helloworld</textarea>
</td>
</tr>
</table>
</form>
</div>

请指教。

【问题讨论】:

  • 忘记 JQuery。你想要彗星光标。 ::鸭子::

标签: jquery css cursor


【解决方案1】:

您也可以在 CSS 中执行此操作:

span.crosshair {cursor:crosshair}
span.help {cursor:help}
span.wait {cursor:wait}

【讨论】:

    【解决方案2】:

    为什么不在mouseover 之外使用$("#closed").css("cursor", "pointer");?默认情况下,只有当鼠标悬停在元素上时才会显示光标。

    但是,如果您从一开始就知道元素#closed 会有一个指针光标,为什么不把它放在样式表中呢?像#closed { cursor: pointer; } 这样的东西。这将使它也适用于禁用 JavaScript 的人。

    【讨论】:

      【解决方案3】:

      $("#closed").css("cursor", "property-value");

      在此处查看可用属性值列表:http://w3schools.com/css/pr_class_cursor.asp

      【讨论】:

        猜你喜欢
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 2018-07-16
        • 2016-09-17
        • 2019-09-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-19
        相关资源
        最近更新 更多