문제

나는 많은 페이지에서 사용할 계획을 가지고 있으며,이 페이지 레이아웃은 일반적인 '검색 ...'을 가지고 있으면이 페이지 레이아웃이 검색 영역 웹 파트가 있습니다.그러나 내가 원하는 것은 그것을 바꾸는 것입니다. 그래서 '당신이 켜져있는 페이지에서 검색을 검색하십시오.'라고 말합니다.나는 내가 켜져있는 페이지의 이름을 얻는 데 어려움을 겪지 않지만 내가 원하는 것을 원하는 initialPrompt를 변경하는 것에 문제가 없습니다.나는 document.getElementById('NBSwebpartSiteSearch').InitialPrompt = 'test';

와 같은 반발 된 것들을 시도했다.

도움이 되었습니까?

해결책

흥미 롭습니다. 2013 년 동작은 검색 상자의 흐림 이벤트에서 함수를 사용하여 '검색 ...'용어를 적절하게 채우거나 숨 깁니다. 자리 표시 자 속성을 사용하는 대신 오래된 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