【问题标题】:GWT resize textarea in IE Internet ExplorerGWT 在 IE Internet Explorer 中调整 textarea 的大小
【发布时间】:2019-02-23 13:57:22
【问题描述】:

我们如何在 GWT 项目的 IE 中调整 textarea 的大小?

可以使用 CSS 调整文本区域的大小,但这在 IE 中不起作用:

.gwt-TextArea {
    resize: vertical;
}

【问题讨论】:

    标签: jquery internet-explorer gwt resizable jquery-ui-resizable


    【解决方案1】:

    我想出了一个使用 JQuery resizable() 方法的解决方案。为了在 GWT 项目中使用它,我使用 JSNI(Javascript Native Interface)将 Javascript 代码集成到 GWT 项目中。

    步骤

    1. 设置我们要在 GWT 中调整大小的小部件的元素 ID。
    2. 将您的 JQuery 库添加到 GWT 项目的起始页(index.html 或 index.jsp)。
    3. 创建 JSNI 方法。该方法将对步骤 1 中设置的元素 id 调用 JQuery resizable() 方法。
    4. 在 GWT.create() 或 uiBinder.createAndBindUi(this) 方法之后的某个时间点在代码中调用 JSNI 方法。

    示例

    步骤1.设置元素ID:

    private final String TEXT_AREA_ID = HTMLPanel.createUniqueId();
    
    textArea.getElement().setId(TEXT_AREA_ID);
    

    第 2 步。在您的 index.html/jsp 页面中添加:

    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    

    第 3 步。创建您的 JSNI 方法:

    public class JSNIResizer
    {
       public static native void resize(String textAreaId) /*-{
          // Internet Explorer. IE 11 uses 'trident'.
          var isIE = ($wnd.navigator.userAgent.match(/msie/i) || $wnd.navigator.userAgent.match(/trident/i));
    
            // Only apply this to IE browsers
            if (isIE) {
    
                var textArea = $wnd.$("#" + textAreaId);
    
                if (textArea) {
                    textArea.resizable({
                        handles : 'n, s' // handle vertical resizing only.
                    });
    
                    // Optional: Adds css styles from jquery-ui.css
                    textArea.addClass("ui-widget-content");
                }
            }
       }-*/;
    }   
    

    请注意,如果您不想将其限制为仅垂直调整大小,则可以这样做:

    textArea.resizable();
    

    步骤 4. 使用要调整大小的元素的 id 调用它:

    JSNIResizer.resize(TEXT_AREA_ID);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多