简体   繁体   English

SharePoint jquery javascript无法运行,但可以从控制台运行

[英]SharePoint jquery javascript does not run but works from console

I have the following code which works from console but does not work on page load. 我有以下代码可从控制台运行,但不适用于页面加载。 The page does not have any error. 该页面没有任何错误。

<div class="nav-report-category">
</div>

<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".ms-listviewtable tr[class='ms-gb']").each(function(){
        alert('test 3');
    });
    var $mydiv = document.getElementsByClassName("nav-report-category")[0];
    var $liTag = document.createElement('li');
    var $aTag = document.createElement('a');


}); 
</script>

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="nav-report-category"> </div> <script src="https://code.jquery.com/jquery-3.0.0.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".ms-listviewtable tr[class='ms-gb']").each(function(){ alert('test 3'); }); var $mydiv = document.getElementsByClassName("nav-report-category")[0]; var $liTag = document.createElement('li'); $mydiv.append($liTag); var $aTag = document.createElement('a'); $mydiv.append($aTag); }); </script> 

Not sure what you are trying to do but if you wanted it in the DOM you have to also append it.If this is the thing that "was not working". 不确定您要做什么,但是如果您想要在DOM中添加它,则还必须附加它。如果这是“不起作用”的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM