gpt4 book ai didi

javascript - 将 PHP 变量作为函数值调用

转载 作者:行者123 更新时间:2023-11-28 07:16:28 25 4
gpt4 key购买 nike

我继承了我们sharepoint网站上的一段代码并且基本上理解它,但是我迷失在PHP中。该代码是一个 Accordion :https://jqueryui.com/accordion/它需要值 1 或 0 来确定默认显示哪个。

我希望这个值每天都改变(忽略月末),所以我创建了一个函数,如果一个月中的某一天是奇数或偶数,则设置 1 或 0。

我的问题是使用函数的输出作为另一个函数的值。我想我需要做一些串联,但我很困惑 JQuery 开始和 PHP 结束的位置

下面的代码不可复制,因为这也是由两个额外的 SharePoint Web 部件提供的,它们生成每个 Accordion 片段的内容,因此我只包含了代码的主要部分。

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>

最佳答案

我尝试了 MattyF 和 Venkat 的建议,但无法让它发挥作用,最终我做的是单独使用 Java 创建一个解决方案。

var day = new Date().getDate();
var checkActive;
if (day % 2 == 0) {//如果天数为奇数,我们将显示我的协作
检查事件= 1;
} 别的 {
检查事件= 0;
}
$("#accordian").find("div").remove(".ms-webpart-chrome-title");
$("#accordian").accordion({ heightStyle: "content"}, {active: checkActive});

我在简单地尝试传递一个我设置的不包含逻辑的变量后得出了这个结论。当使用 java VAR 工作时,构建 IF 是一件很快的事情。正如我的问题中所说,我对这些语言很陌生,所以当我第一次看到 $ 时,我假设是 PHP,尽管我后来意识到这只是在 JQuery 中调用 THIS...

感谢您的帮助,并对我的无知表示歉意

关于javascript - 将 PHP 变量作为函数值调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30790503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com