jQuery 可选定制

2023-12-02

我有一个 jQuery 可供选择,如下所示。它实际上是一个有序列表。有序列表位于名为 myBorderDiv 的 div 内。

当我按下 control 并将鼠标悬停在项目上时,所有项目都会出现不需要的效果(在 IE8 中),如下图所示。如何克服这个问题?

enter image description here

<html xmlns="http://www.w3.org/1999/xhtml">

<title></title>

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/themes/sunny/jquery-ui.css"
    rel="stylesheet" type="text/css" />

<script type="text/javascript">

    $(document).ready(function () {

        //Make it as selectable
        $("#myOrderedListSelecatableAsHeaderPart").selectable();


        //selectablestop Event Handler
        $("#myOrderedListSelecatableAsHeaderPart").bind("selectablestop", function (event) {
            var test= "";
            $(".ui-selected", this).each(function () {
                test+= this.getAttribute("Categoryid") + ",";
            });


        });

        $("button, input:submit").button()

        $("button#selectall").click(function (event) {
            //When select all button clicked 

            //Add css class
            $("#myOrderedListSelecatableAsHeaderPart li").addClass("ui-selected");

            //Trigger the selectablestop event and preventDefault
            $("#myOrderedListSelecatableAsHeaderPart").trigger("selectablestop");
            event.preventDefault();

        });


    });


</script>
<style type="text/css">
    #myOrderedListSelecatableAsHeaderPart .ui-selected
    {
        background: #F39814;
        color: white;
    }

    #myOrderedListSelecatableAsHeaderPart
    {
        list-style-type: none;
        margin: 0;
        padding: 0;
        text-align: center;
    }

    #myOrderedListSelecatableAsHeaderPart li
    {
        margin: 3px;
        height: 18px;
        padding: 3px; /*Display list items in blobk */
        display: inline-block;
    }
    </style>
</head>


<body>



<div>
    <h3>
        Hold control and click to select multiple items
    </h3>
    <div>

        <div id="myBorderDiv" style="border: 1px solid brown; width:375px;">

            <ol id="myOrderedListSelecatableAsHeaderPart"  >
                <li categoryid="2" class="ui-widget-content">Apple </li>
                <li categoryid="4" class="ui-widget-content">Bag </li>
                <li categoryid="10" class="ui-widget-content">Cup </li>
                <li categoryid="7" class="ui-widget-content">Doll </li>
                <li categoryid="8" class="ui-widget-content">Empty </li>
                <li categoryid="9" class="ui-widget-content">Football </li>
                <li categoryid="10" class="ui-widget-content">Gems </li>
                <li categoryid="50" class="ui-widget-content">Horse </li>
                <li categoryid="3" class="ui-widget-content">Inter </li>
                <li categoryid="4" class="ui-widget-content">JokerCap </li>
                <li categoryid="5" class="ui-widget-content">King </li>
                <li categoryid="6" class="ui-widget-content">Lemon </li>
                <li categoryid="7" class="ui-widget-content">Nail </li>
                <li categoryid="8" class="ui-widget-content">One </li>
                <li categoryid="9" class="ui-widget-content">Ping </li>
                <li categoryid="10" class="ui-widget-content">Quick </li>
                <li categoryid="7" class="ui-widget-content">Royal </li>
                <li categoryid="8" class="ui-widget-content">Standard </li>
                <li categoryid="9" class="ui-widget-content">Train </li>
                <li categoryid="10" class="ui-widget-content">Umbrella </li>
                <li categoryid="50" class="ui-widget-content">Van </li>
            </ol>
        </div>
        <br />
        <button id="selectall">
            Select All</button>
    </div>
</div>


这段代码删节自此answer将解决问题

$(function(){
    $.extend($.fn.disableTextSelect = function() {
                $(this).bind('selectstart',function(){return false;});
    });
    $('#myOrderedListSelecatableAsHeaderPart').disableTextSelect();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jQuery 可选定制 的相关文章

随机推荐

  • 如何编写比较对象的compareTo方法?

    我正在学习数组 基本上我有一个收集姓氏 名字和分数的数组 我需要写一个compareTo方法将比较姓氏 然后比较名字 以便列表可以从姓氏开始按字母顺序排序 然后如果两个人具有相同的姓氏 那么它将对名字进行排序 我很困惑 因为我书中的所有信息
  • Datetime.ToString 在 .NET6 中为月份缩写添加点

    我有这个简单的 C 代码示例 它为发票创建一个文件名 var x new DateTime 2022 8 26 var invoiceNumber 1100 var fileName CustomerX Invoice fileName i
  • Typo3 Extbase Repository->findAll() 返回空

    我就是不能找到所有 即使我能够通过以下方式访问特定记录 也会返回任何内容通过Uid查找 我已经注意到 并尝试解决方法 设置 打字稿解决方案和记录存储页面bug没有任何成功 我正在使用一个由扩展构建器创建的虚拟扩展代码为了您的方便 在 TYP
  • 如何用 C# 锁定文件?

    我不确定人们通常所说的 锁定 文件是什么意思 但我想要的是对一个文件执行此操作 当我尝试用另一个文件打开它时 该文件将产生 指定的文件正在使用 错误消息应用 我想这样做是为了测试我的应用程序 看看当我尝试打开处于此状态的文件时它的行为如何
  • SLF4J:类路径包含多个 SLF4J 绑定警告

    我在其他问题中看到 通常此警告的解决方案是将 slf4j 从导致此冲突的依赖项中排除 但我无法在我的项目中发现问题 SLF4J Class path contains multiple SLF4J bindings SLF4J Found
  • 使用 AJAX 更新后 Jquery 点击不起作用

    我已经阅读了一些关于我的问题的内容 但仍然没有得到正确的答案 我尝试了 on 方法 它仍然不起作用 我正在使用 Laravel foreach orders as order tr class td order menus name td
  • 如何清除徽章号码同时保留通知中心

    I use UIApplication sharedApplication setApplicationIconBadgeNumber 0 清除徽章号码 它工作正常 但远程通知同时被删除 还有许多其他问题需要清除通知中心 但我不想清除它们
  • SQL 查询澄清

    我有两张桌子医生和计费 我希望查看治疗多名患者的医生的姓名 医生编号和总费用 doctor表列如下 doctorid dname 计费表列如下 billid patientid doctorid fees 我尝试了以下代码 但出现错误 指出
  • 如何在 Android/Linux 上构建 OpenSSL ?

    你好 我需要为 Android NDK r5b 构建 OpenSSL 库 今天将是我的 useles 战斗的第二天 这是我所做的简短列表 下载 https github com fries android external openssl
  • 扩展 HashMap 并仅同步 put

    我最近在我们的代码库中遇到一个类 它扩展了 HashMap 并同步了 put 方法 除了比使用 ConcurrentHashMap 效率低之外 扩展 HashMap 并仅同步 put K V 可能会出现什么样的问题 假设我们不关心 get
  • 如何ajax jsf 2输出链接

    我想制作一个可以在ajax上运行的网页 一切ajax 我的意思是 每当您单击链接 我指的是 来使用另一个链接中的数据更改某个 div 时 例如
  • 如何使用 Jersey JSON POJO 支持?

    我有一个对象 我想将其作为 RESTful 资源以 JSON 形式提供 我像这样打开了 Jersey 的 JSON POJO 支持 在 web xml 中
  • 比较两个枚举变量,无论它们的关联值如何

    考虑这个枚举 enum DataType case One data Int case Two value String Swift 具有模式匹配来将枚举与关联值进行比较 如下所示 let var1 DataType One data 12
  • img.onerror 似乎不适用于 IE8

    我正在尝试从网址加载图像来检查互联网连接 当没有互联网连接时 它应该显示一个 dojo 警告对话框 这适用于 Firefox 但不适用于 IE8 以下是代码片段 var img new Image img src userGuideUrl1
  • 您可以从扩展程序访问 chrome:// 页面吗?

    当你编写manifest json文件时 你必须指定matches用于您的内容脚本 这http and https工作正常 但如果我尝试包括chrome 或其任何变体 我收到错误消息 指出我正在尝试对我的应用程序使用无效的方案matches
  • 如何防止 Visual Basic 2012 中以下代码的 SQL 注入

    我对如何防止 SQL 注入感到困惑 我在网上查看过 我是使用存储过程 还是创建变量 我完全迷失了 Try connection Open we got here so our connection to the db is sound ch
  • Windows Phone 8 模拟器仅返回雷蒙德位置

    我正在使用以下代码 Geolocator myGeolocator new Geolocator DesiredAccuracy PositionAccuracy High Geoposition myGeoposition await m
  • WPF - 跨线程事件

    我的问题是我想使用新线程在画布中添加项目 所以我有多个方法 底部的示例 它们生成例如图像并设置一些属性 然后他们应该通过事件回调生成的思考 以下是我调用的为画布生成想法的线程的一部分 Here I create the event in t
  • 将表名作为参数传递给 SqlCommand 的问题

    这个问题的目标是避免SQL注入 我有查询 选择 插入 更新 删除 当我需要发送表名作为参数时 我该怎么做 我将非常感谢你的帮助 insertCommand CommandText update tableName set code code
  • jQuery 可选定制

    我有一个 jQuery 可供选择 如下所示 它实际上是一个有序列表 有序列表位于名为 myBorderDiv 的 div 内 当我按下 control 并将鼠标悬停在项目上时 所有项目都会出现不需要的效果 在 IE8 中 如下图所示 如何克