質問

私は私が多くのページで使用される予定のpage_layoutを持っています、このページレイアウトは検索ボックスのウェブパートを持っています、現時点では一般的な '検索...'を持っています。しかし、私が欲しいものはそれを変更することです。私は私がオンしているページの名前を取得するのに苦労していませんが、私が欲しいものに初期宣伝を変更します。document.getElementById('NBSwebpartSiteSearch').InitialPrompt = 'test';

のような大胆なものを試しました

役に立ちましたか?

解決

面白い - 2013年の振る舞いは、検索ボックスのBlurイベントで機能を使用して、必要に応じて「検索...」という用語を入力または非表示にします。 - PlaceHolderプロパティを使用する代わりに、古いIEバージョンをサポートすると思います。...

だから!あなたが必要とするものは:

//use this instead of immediate or jQuery ready because we want to manipulate SP generated markup
_spBodyOnLoadFunctionNames.push("searchPromptSetup");

function searchPromptSetup() {
    function spPromptHider(searchDOMElement) {
        //make sure you have a valid object 
        if (searchDOMElement) {
            //give it a placeholder if it doesn't already have one
            if (!searchDOMElement.placeholder) searchDOMElement.placeholder = "Search in whatever page you are on";
            /*use SP's javascript to hide the 'Search...' prompt, note the $ here is not the jQuery alias...
                the OR assignment is my lazy way of allowing the function to be used in the blur event later... */
            var control = $getClientControl(searchDOMElement) || $getClientControl(this);
            control.hidePrompt();
        }
    }

    var searchBox = document.getElementById('<yoursearchboxid>');
    // if you don't add this listener to the blur event it will just reset to 'Search...'
    searchBox.addEventListener("blur", spPromptHider);
    spPromptHider(searchBox);
}
.

上記は、プレースホルダ属性をサポートするブラウザでのみ機能します...ではなく、そうでない方のサポートを追加することができます。

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top