是否有办法编辑此脚本,使其仅适用于特定的选择类

Is there a way to edit this script so that it only applies to a specific select class?

本文关键字:适用于 选择 编辑 脚本 是否      更新时间:2023-09-26

是否有一种方法来编辑这个脚本,使它只适用于一个特定的选择类,而不是一个页面内的所有标签?

(此脚本用于扩展下拉列表选项,以便它们在IE中不被切断。)我们想要的是只将此应用于选择选项名称很长的标签。

<script>// Safely use $
    (function($) {
      $.fn._ie_select=function() { 
        return $(this).each(function() { 
          var a = $(this),
              p = a.parent();
          p.css('position','relative');
          var o = a.position(),
              h = a.outerHeight(),
              l = o.left,
              t = o.top;
          var c = a.clone(true);
          $.data(c,'element',a);
          c.css({
            zIndex   : 100,
            height   : h,
            top      : t,
            left     : l,
            position : 'absolute',
            width    : 'auto',
            opacity  : 0
          }).attr({
            id    : this.id + '-clone',
            name  : this.name + '-clone'
          }).change(function() {
            $.data(c,'element')
              .val($(this).val())
              .trigger('change')
          });
          a.before(c).click(function() { 
            c.trigger('click');
          });
        }); // END RETURN
      }; // END PLUGIN
      if ($.browser.msie) {
        $('select')._ie_select();
      }
    })(jQuery); // END SAFETY</script>

底部的代码似乎是使用选择器的部分,因此更改

if ($.browser.msie) {
   $('select')._ie_select();
}

if ($.browser.msie) {
   $('select.classNameHere')._ie_select();
}