-1

我有带有图标的按钮,我想在将鼠标悬停在该图标上时附加工具提示。

但它不起作用,请参见下面的示例:

$(document).ready(function() {
  $("#primaryTextButton").kendoButton({
    icon: "filter-clear"
  });
  $("#textButton").kendoButton({
    icon: "filter-clear"
  });

  var tooltip = $("#example").kendoTooltip({
    filter: "button[tooltip] > span",
    position: "top",
    content: function(e) {
      var target = e.target;
      if (target.parent().attr("tooltip")) {
        return target.parent().attr("tooltip");
      } else {
        return null;
      }

    }
  });
});
.demo-section p {
  margin: 0 0 30px;
  line-height: 50px;
}

.demo-section p .k-button {
  margin: 0 10px 0 0;
}

.k-primary {
  min-width: 150px;
}
<!DOCTYPE html>
<html>

<head>
  <base href="https://demos.telerik.com/kendo-ui/button/index">
  <style>
    html {
      font-size: 14px;
      font-family: Arial, Helvetica, sans-serif;
    }
  </style>
  <title></title>
  <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.common-bootstrap.min.css" />
  <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.bootstrap.min.css" />
  <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.bootstrap.mobile.min.css" />
  <script src="https://kendo.cdn.telerik.com/2018.2.516/js/jquery.min.js"></script>
  <script src="https://kendo.cdn.telerik.com/2018.2.516/js/kendo.all.min.js"></script>
</head>

<body>
  <div id="example">
    <div class="demo-section k-content">
      <div>
        <h4>Basic Button</h4>
        <p>
          <button id="primaryTextButton" class="k-primary" tooltip="Example of tool tip">Primary Button</button>
          <button id="textButton">Button</button>
        </p>
      </div>
    </div>
  </div>

</body>

</html>

- - - - - -更新 - - - - - - - - -

使用 HTML 按钮有效。带有.k-button类的东西。

请参见下面的带有 HTML 按钮的工作示例:

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/button/index">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.common-bootstrap.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.bootstrap.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.bootstrap.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2018.2.516/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2018.2.516/js/kendo.all.min.js"></script>
    

</head>
<body>

        <div id="example">
            <div class="demo-section k-content">
                <div>
                    <h4>Basic Button</h4>
                    <p>
				
							
							<button id="primaryTextButton" tooltip="Example of tool tip!" >Primary Button
							<span class="k-icon k-i-info">
							</button>
							</span>
						
					
						
                        <button id="textButton">Button
						<span class="k-icon k-i-info"></span></button>
                    </p>
                </div>

             

            <script>
                $(document).ready(function () {
                    

                    $("#textButton").kendoButton({
                    
                    });

                  
                  var tooltip = $("#example").kendoTooltip({
                                filter: "span",            
                                position: "top",
                                content: function (e) {
                                    var target = e.target;                              
                                    if (target.parent().attr("tooltip")) {
                                        return target.parent().attr("tooltip");
                                    } else {
                                        return null;
                                    }
                
            },
			show: onShow,
                        hide: onHide,
        });
		
		 function onShow(e) {
                    console.log("event :: show");
                }

                function onHide(e) {
                    console.log("event :: hide");
                }
		
                });
            </script>

            <style>
                .demo-section p {
                    margin: 0 0 30px;
                    line-height: 50px;
                }
                .demo-section p .k-button {
                    margin: 0 10px 0 0;
                }
                .k-primary {
                    min-width: 150px;
                }
				.k-icon{
					padding: 10px;
					font-size: 32px;
				}
            </style>
        </div>

</body>
</html>

4

1 回答 1

-1

您试图span在图标实际存在之前将其作为目标元素,因此您的过滤器失败了。

如果您将过滤器更改为此,您仍然可以在按钮悬停时显示工具提示:

filter: "button[tooltip]"

显然,这假设您不需要仅在 ICON 悬停时显示工具提示,但这取决于您的要求。:)

于 2018-05-18T21:51:53.743 回答