2015-05-06 50 views
0

我有一個param函數,我必須從NavDropdownListContainer動態獲取數據,並使用JQuery或JavaScript將其設置在搜索文本框中。動態更改SharePoint 2013搜索摘要中的內容

請在下面找到與之相關的截圖和css。

SharePoint 2013 SearchBox

幫助,將不勝感激。

<div class="ms-floatLeft" id="SearchBox" name="Control"> 
    <div class="ms-srch-sbLarge ms-srch-sb-borderFocused" id="ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_sboxdiv"> 
     <input title="Search Everything" class="ms-textLarge ms-srch-sbLarge-navWidth ms-srch-sb-prompt ms-helperText" id="ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_sbox" accesskey="S" onkeydown="var ctl = $getClientControl(this);ctl.activateDefaultQuerySuggestionBehavior();" onkeypress="if (Srch.U.isEnterKey(String.fromCharCode(event.keyCode))) { $getClientControl(this).search(this.value);return Srch.U.cancelEvent(event); }" onfocus="var ctl = $getClientControl(this);ctl.hidePrompt();ctl.setBorder(true);" onblur="var ctl = $getClientControl(this);ctl.showPrompt();ctl.setBorder(false);" type="text" maxlength="2048" value="" autocorrect="off" autocomplete="off"> 
     <a title="Navigation" class="ms-srch-sb-navLink ms-srch-sb-navLink-menuOpen" id="ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_NavButton" onclick="$getClientControl(this).activateDefaultNavigationBehavior();return Srch.U.cancelEvent(event);" href="javascript: {}"> <img class="ms-srch-sbLarge-navImg" id="navImg" alt="Navigation" src="/_layouts/15/images/searchresultui.png?rev=23"> </a> 
     <a title="Search" class="ms-srch-sb-searchLink" id="ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_SearchLink" onclick="$getClientControl(this).search($get('ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_sbox').value);" href="javascript: {}"> <img class="ms-srch-sbLarge-searchImg" id="searchImg" alt="Search" src="/_layouts/15/images/searchresultui.png?rev=23"> </a> 
     <div class="ms-qSuggest-container ms-shadow" id="AutoCompContainer"> 
      <div id="ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_AutoCompList"></div> 
     </div> 
     <div class="ms-qSuggest-container ms-shadow" id="NavDropdownListContainer" style="display: block; visibility: visible; position: absolute;"> 
      <div class="ms-qSuggest-list" id="ctl00_ctl38_g_c60051d3_9564_459e_8a40_e91f8abf4dcf_csr_NavDropdownList" style="width: 498px;"> 
       <div class="ms-qSuggest-hListItem">Everything</div> 
       <div class="ms-qSuggest-listItem">Videos</div> 
       <div class="ms-qSuggest-listItem">People</div> 
       <div class="ms-qSuggest-listItem">Conversations</div> 
      </div> 
     </div> 
    </div> 
</div> 

回答

0

我修改後的代碼如下所示,其中位於下的網站設置> Web設計畫廊>母版頁和頁面佈局>顯示模板>搜索了「Control_Searchbox.html」:

//alert('Ready'); 
    var searchScope = GetUrlKeyValue("searchscope", false, location.href); 
    //alert(searchScope); 

    if(searchScope != ""){ 
     var navNodes = ctx.ClientControl.get_navigationNodes(); 
     //alert(navNodes); 
     if (navNodes.length > 0) { 
       var nodeName; 
       var nodePromptString; 
       var nodeUrl; 

       for (var i = 0; i < navNodes.length; ++i) { 
        nodeName = navNodes[i].name; 
        nodePromptString = navNodes[i].promptString; 
        nodeUrl = navNodes[i].url; 

        //alert(nodeName + '/' + nodePromptString + '/' + nodeUrl + ' - ' + searchScope); 

        if(nodeName.toUpperCase() == searchScope.toUpperCase()){ 
         ctx.ClientControl.set_resultsPageAddress(nodeUrl);    
         prompt = nodePromptString; 
         break; 
        } 
       } 
     } 
    } 

因此每當你想獲得的結果來源之一,你必須通過查詢字符串作爲

http://siteurl/Search/Seiten/default.aspx?searchscope=Everything 

完全Control_SearchBox.html