简体   繁体   English

在SharePoint Web部件中设置焦点和onblur事件的InputFormTextBox

[英]InputFormTextBox setting an focus and a onblur event, in a SharePoint web part

I'm making use of a bunch of InputFormTextBoxes and I'd like to have an onblur event get fired when the box is no longer in focus. 我正在使用一堆InputFormTextBoxes,并且当框不再聚焦时,我希望触发onb​​lur事件。 This is when RichText == true. 这是RichText == true时。

This is because I have a Sharepoint Webpart that has a lot of editable areas and richtext is required. 这是因为我有一个Sharepoint Webpart,它具有很多可编辑区域,并且需要RTF。 However, the screen gets cluttered if they are all available. 但是,如果它们都可用,则屏幕会变得混乱。 So I'm making it autosave and hide the text box when the user clicks away. 因此,当用户单击时,它会自动保存并隐藏文本框。 This saves screen real estate, and improves the page performance greatly. 这样可以节省屏幕空间,并大大提高页面性能。

I can get this to work with RichText == false, so it's just a normal TextArea HTML control. 我可以将其与RichText == false一起使用,因此它只是普通的TextArea HTML控件。 However, I can't set focus with JavaScript on the textarea, and I can't get an event to fire for the onblur event. 但是,我无法将JavaScript放在文本区域上,也无法为onblur事件触发事件。

You can do this fairly easily with javascript. 您可以使用javascript轻松完成此操作。 If I understand your requirements, you have large text areas that you want to expand and collapse dynamically as the user moves in and out of them. 如果我理解您的要求,则您需要在较大的文本区域中随用户移入或移出它们而动态扩展和折叠。 That way you don't take up so much real estate. 这样,您就不会占用太多房地产。 I tested this code on a normal edit page with two multi-line textboxes. 我在带有两个多行文本框的普通编辑页面上测试了此代码。 You'll probably need to adjust for your web part. 您可能需要针对自己的Web部件进行调整。

$(function(){
    var collapsedHeight = 18;
    var expandedHeight = 50;
    var editors = $("iframe[title='Rich Text Editor']");
    editors.attr("height", collapsedHeight);
    editors.blur(function(){
        $(this).attr("height", collapsedHeight);
    });
    editors.focus(function(){
        $(this).attr("height", expandedHeight);
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM