【发布时间】:2019-02-23 13:57:22
【问题描述】:
我们如何在 GWT 项目的 IE 中调整 textarea 的大小?
可以使用 CSS 调整文本区域的大小,但这在 IE 中不起作用:
.gwt-TextArea {
resize: vertical;
}
【问题讨论】:
标签: jquery internet-explorer gwt resizable jquery-ui-resizable
我们如何在 GWT 项目的 IE 中调整 textarea 的大小?
可以使用 CSS 调整文本区域的大小,但这在 IE 中不起作用:
.gwt-TextArea {
resize: vertical;
}
【问题讨论】:
标签: jquery internet-explorer gwt resizable jquery-ui-resizable
我想出了一个使用 JQuery resizable() 方法的解决方案。为了在 GWT 项目中使用它,我使用 JSNI(Javascript Native Interface)将 Javascript 代码集成到 GWT 项目中。
步骤
示例
步骤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);
【讨论】: