Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript _保存sharepoint网站时,spBodyOnLoadFunctionNames.push不起作用_Javascript_Jquery_Sharepoint_Alert - Fatal编程技术网

Javascript _保存sharepoint网站时,spBodyOnLoadFunctionNames.push不起作用

Javascript _保存sharepoint网站时,spBodyOnLoadFunctionNames.push不起作用,javascript,jquery,sharepoint,alert,Javascript,Jquery,Sharepoint,Alert,我创建了一个方法来验证共享点站点中的输入字段,您可以在下面的代码中看到。 问题是该方法应该在保存时激活,但它没有激活。 现在,它是激活的文件准备,这不是我想要的。 有什么建议吗 </script> <script type="text/javascript"> $(document).ready(function(){ ValidateFields(); }); function ValidateFields() { if ((document

我创建了一个方法来验证共享点站点中的输入字段,您可以在下面的代码中看到。 问题是该方法应该在保存时激活,但它没有激活。 现在,它是激活的文件准备,这不是我想要的。 有什么建议吗

 </script>


 <script type="text/javascript">


  $(document).ready(function(){


 ValidateFields();

});

function ValidateFields()
{
 if ((document.querySelector('input[name$="BooleanField"]').checked ==false) 
 && ($("select[title='Employees selected values'] option").length==0)) 
 {
// $("select[title='Employees selected values'] option").length==0).text("<p> 
  Please check All employees in department OR select employees </p>");
  // // checked, so do something
  alert ("Please check All employees in department OR select employees")
 }

 if ((document.querySelector('input[name$="BooleanField"]').checked ==true) 
 && ($("select[title='Employees selected values'] option").length==1)) {


  alert ("Please check All employees in department OR select employees23")

 }



}

_spBodyOnLoadFunctionNames.push("ValidateFields()");

$(文档).ready(函数(){
ValidateFields();
});
函数ValidateFields()
{
if((document.querySelector('input[name$=“BooleanField”]”)。选中==false)
&&($(“选择[title='Employees selected values']选项”)。长度==0)
{
//$(“选择[title='Employees selected values']选项”)。长度==0。文本(
请勾选部门所有员工或选择员工

”; ////检查过了,所以做点什么 警报(“请检查部门中的所有员工或选择员工”) } if((document.querySelector('input[name$=“BooleanField”]”)。选中==true) &&($(“选择[title='Employees selected values']选项”)。长度==1){ 警报(“请检查部门中的所有员工或选择员工23”) } } _spBodyOnLoadFunctionNames.push(“ValidateFields()”);

您需要覆盖表单的“提交”处理程序。根据按钮的ID,这可能会起作用:

$(document).ready(function() {
    $("input[id$='SaveItem']").each(function() {

        // get the button
        var button = $(this);

        // reference the existing handler for later use
        var existingHandler = this.onclick;

        // clear the existing handler
        this.onclick = null;

        // add your custom handler that validates first, then "submits" if successful
        button.click(function() {
            if(ValidateFields()){ // change ValidateFields to return true/false
                 existingHandler(); // validation passed, now call original handler
            }
        });
    });
});

我们可以使用预埋法来实现它。以下代码供您参考

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
function PreSaveAction(){
    if ((document.querySelector('input[name$="BooleanField"]').checked ==false)&& ($("select[title='Employees selected values'] option").length==0)){
        // checked, so do something
        alert ("Please check All employees in department OR select employees");
        return false;
    }
    if ((document.querySelector('input[name$="BooleanField"]').checked ==true)&& ($("select[title='Employees selected values'] option").length==1)) {
        alert ("Please check All employees in department OR select employees23");
        return false;
    }
    return true;
}
</script>

函数PreSaveAction(){
if((document.querySelector('input[name$=“BooleanField”]')。checked==false)和($($select[title='Employees selected values']option”)。长度==0){
//检查过了,所以做点什么吧
警报(“请检查部门中的所有员工或选择员工”);
返回false;
}
if((document.querySelector('input[name$=“BooleanField”]”)。checked==true)和($($('select[title='Employees selected values']选项”)。长度==1)){
警报(“请检查部门中的所有员工或选择员工23”);
返回false;
}
返回true;
}