2017-04-06 56 views
0

我在SharePoint(aspx)中有一個頁面。我試圖隱藏一個使用jQuery的td控件。我已附加從開發人員工具和jQuery呈現的HTML。的jsfiddle在這裏https://jsfiddle.net/savo0mme/1/jQuery隱藏一個元素,但它不起作用

HTML代碼

<table class="ms-WPBody" style="padding-top: 0px; width: 100%;"> 
        <tbody><tr> 
         <td valign="top" style="padding-left:4px;padding-right:4px;"></td><td id="ctl00_m_g_1c59424a_162b_4285_8f9a_33109bdfc04f_DefaultValueMessage" width="100%" style="padding-left:4px;padding-right:4px;">The default value specified is not valid.</td> 
        </tr> 
       </tbody> 
</table> 

jQuery代碼

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> </script> 

<script type="text/javascript"> 
    $(function() { 

     var filterErrorText = "ctl00_m_g_1c59424a_162b_4285_8f9a_33109bdfc04f_DefaultValueMessage"; 
     var filterErrorTextID = document.getElementById(ctl00_m_g_1c59424a_162b_4285_8f9a_33109bdfc04f_DefaultValueMessage).innerText; 
     alert(document.getElementById("ctl00_m_g_1c59424a_162b_4285_8f9a_33109bdfc04f_DefaultValueMessage").innerText); 
     alert(filterErrorTextID); 
    /* if(filterErrorTextID) 
     { 
      alert(filterErrorTextID); 
      //filterErrorTextID.style.display="none"; 
     } */ 
    }); 
</script> 
+0

我沒有看到你的任何企圖隱藏'td'元素。你在這裏有兩個,但不清楚究竟是哪一個。如果你真的想隱藏它,你應該首先使用谷歌搜索解決方案,我相信你應該自己解決這個問題。 –

+0

不要將DOM調用與您的jQuery混合使用。使用一個或另一個。您可能需要'$('#'+ filterErrorText).hide()' – Cfreak

+0

只是一個建議:不要在共享點使用像這樣的「ctl00_m_g_1c59424a_162b_4285_8f9a_33109bdfc04f_DefaultValueMessage」這樣的ID來定位一個元素。始終使用div [id $ =「_ DefaultValueMessage」]。 – Vaibhav

回答

1

您的腳本不使用jquery。 你應該使用jQuery hide()函數,如

$('#ctl00_m_g_1c59424a_162b_4285_8f9a_33109bdfc04f_DefaultValueMessage').hide(); 
+0

jQuery隱藏功能完美運行。但是,我必須評估該控件是否包含文本。這就是爲什麼我嘗試使用innerHtml或innerText提醒,但沒有人會使用 –

+0

使用jQuery,有.text()函數 它返回內部文本。 – Cyril