2017-04-10 38 views
1

我需要在點擊按鈕後禁用搜索按鈕。這需要附加在以下代碼中。如何在點擊後禁用搜索按鈕

<form class="search-head" id="frmSearch" action="<%= resultString %>" method="get"> 
    <input name="q" class="<%=cssName%> search-tags" id="tags" value="q" maxlength=50 /> 

    <input type="hidden" name="_charset_" value="utf-8" /> 
    <input type="hidden" id="searchLabel" name="searchLabel" value='<%=currentStyle.get("searchLabel", "")%>' /> 
     <c:if test="${enableSpringerSearch eq true}"> 
      <button type="button" class="change-search-engine">${springerButtonLabel}</button> 
     </c:if> 
    <button type="submit"><fmt:message key="label_button"/></button> 

任何幫助將不勝感激!

+0

那你審視自己?看看onclick事件。 –

回答

0

您可以創建一個單獨的函數來處理它:

document.getElementById("idOfButton").onclick = function() { 
    //disable 
    this.disabled = true; 
} 
+0

謝謝。但是我怎麼能把這個嵌入到上面的代碼中。我可以在

+0

之後添加一個id給你的按鈕,比如'

0

function disableBtn() { 
 
    document.getElementById("btn").disabled = true; 
 
}
<input type="hidden" name="_charset_" value="utf-8" /> 
 
<input type="hidden" id="searchLabel" name="searchLabel" value='<%=currentStyle.get("searchLabel", "")%>' /> 
 
    <c:if test="${enableSpringerSearch eq true}"> 
 
     <button id="btn" type="button" onclick="disableBtn()" class="change-search-engine">search</button> 
 
    </c:if> 
 
<button type="submit" ><fmt:message key="label_button"/></button>

+0

它不起作用,代碼顯示在搜索圖標附近。 \t '/> function disableBtn(){ document.getElementById(「btn」)。disabled = true; } –