duanfen2008 2015-06-11 20:10
浏览 64
已采纳

将PHP变量称为函数值

I inherited a piece of code on our sharepoint site and understand it basically, but I am lost in the PHP. The code is an accordion: https://jqueryui.com/accordion/ And it takes a value of 1 or 0 to determine which is shown by default.

I want this value to change each day (ignoring end of months), so I made a function which sets 1 or 0 if the day of month is odd or even.

My issue is using the output of my function as the value for this other function. I think I'll need to do some concatenation but I'm confused where the JQuery begins and PHP ends

Code below, it is not replicable because this is also fed by two additional SharePoint webparts which generate the content of each accordion piece, so I only included the meat of the code.

Look for $checkActive this is used in my function and is my desired value for the final lines

 jQuery(document).ready(function($) {
     var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
      if (inDesignMode == "1")
      {

      }
      else
      {
         //Put the WebPart Title for all the Web Parts you wish
         //to put into the jQuery UI Accordion into the array below.
         //Accordian(["MY TO-DO LIST","MY COLLABORATION","MY TEAMSITES"]);
     //Accordian(["MY FAVORITES","MY TEAMSITES","MY COLLABORATION"]);
        Accordian(["MY COLLABORATION","IN THE NEWS"]);

      }

        });

function Accordian(webPartTitles)
{
    for(index in webPartTitles)
    {
        var title = webPartTitles[index];
        $("#accordian").append('<h3>'+title+'</h3>');

        var addedToAccordion = 'false';
        $("span:contains('"+title+"')").each(function(){

            if ($(this).html() == title && addedToAccordion == 'false' ){
                if($(this).closest("span").closest("[id^='MSOZoneCell_WebPart']").contents().length > 0)
               {
                   $(this).closest("span").hide().closest("[id^='MSOZoneCell_WebPart']").contents().appendTo($("#accordianTemp")); 
                   addedToAccordion = 'true';
                    $("span:contains('"+title+"Link')").each(function(){

                         if ($(this).html() == title + "Link"){
                            if($(this).closest("span").closest("[id^='MSOZoneCell_WebPart']").contents().length > 0)
                             {
                                 $(this).closest("span").hide().closest("[id^='MSOZoneCell_WebPart']").contents().appendTo($("#accordianTemp")); 
               }
            }

        });

               }
            }
        });
        $("#accordian").append("<div>" + $("#accordianTemp").html() + "</div>");
        $("#accordianTemp").empty();
              }

    $dw = date( "j", time());
    $checkActive = ($dw % 2 == 0) ? '1' : '0'; // If the day number is Odd, we will show My Collaboration

the active value below is what normally accepts 1 or 0 but I want it to take my variable value

    $("#accordian").find("div").remove( ".ms-webpart-chrome-title" );
    $("#accordian").accordion({ heightStyle: "content" }, {active:$checkActive });
}</script> 
  • 写回答

2条回答 默认 最新

  • dt97868 2015-06-12 12:35
    关注

    I tried what MattyF and Venkat suggested, and I couldn't get it to work, and what I ended up doing was creating a solution using Java alone.

    var day = new Date().getDate(); var checkActive; if (day % 2 == 0) { // If the day number is Odd, we will show My Collaboration checkActive = 1; } else { checkActive = 0; } $("#accordian").find("div").remove( ".ms-webpart-chrome-title" ); $("#accordian").accordion({ heightStyle: "content" }, {active: checkActive});

    I reached this conclusion after simply trying to pass a variable which I set, containing no logic. When that worked using java VAR, it was a quick matter of building the IF. As said in my question, I am new to these languages so when I first saw $ I assumed PHP, although I later realized that was simply calling THIS in the JQuery...

    I appreciate the help and apologize for my ignorance

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?