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条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值