jQuery widget:将 widget 限制为选定的标签

jQuery widget: restricting widgets to selected tags

本文关键字:widget 标签 jQuery      更新时间:2023-09-26

我想将我的小部件的构造限制为仅<table>元素。这在我的插件的小部件前版本中很容易,我正在测试tagName.

if (this.element[0].tagName.toLowerCase() !== 'table')

如果tagName不合适,我只是返回jQuery对象以确保可链接性。

我将如何在小部件工厂的顶部进行操作?

从 http://jqueryui.com/widget/中获取样本

$.widget( "custom.mywidget", {
// the constructor
_create: function() {
   if(this.element.tagName.toLower() !== 'table') throw "mywidget requires tableelement";