GVKun编程网logo

PHP:如何从数组中动态输入选项卡中的值?(php动态创建数组)

4

以上就是给各位分享PHP:如何从数组中动态输入选项卡中的值?,其中也会对php动态创建数组进行解释,同时本文还将给你拓展c#–什么是C中的数组^T以及如何从数组中提取值?、java–如何从数组中选择一

以上就是给各位分享PHP:如何从数组中动态输入选项卡中的值?,其中也会对php动态创建数组进行解释,同时本文还将给你拓展c# – 什么是C中的数组^ T以及如何从数组中提取值?、java – 如何从数组中选择一个值?、javascript – 如何从origin选项卡中获取新打开的浏览器选项卡名称?、jQuery UI选项卡转到选项卡中的特定div等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

PHP:如何从数组中动态输入选项卡中的值?(php动态创建数组)

PHP:如何从数组中动态输入选项卡中的值?(php动态创建数组)

我有一个 PHP数组,其中我有一些相关的信息来回应这样.

<?PHP 

    $options = array(

        array("name" => "Title","desc" => "Description","type" => '_one',"tab-name" => "Tab 1"

        ),array("name" => "Title2","desc" => "Description2","type" => '_two',"tab-name" => "Tab 2"

        ),array("name" => "Title3","desc" => "Description3","type" => '_three',"tab-name" => "Tab 3"

        )

    )

?>

我已经做了一个函数来回显出名称,desc,这是完美的

这里是:

<?PHP

function create_heading($value) {
    echo '<h2>'.$value['name'].'</h2>';
}
function create_description($value){
    echo '<p>'.$value['desc'].'</p>'
}

function wrapper1($value) {
    echo '<h1>This is the wrapper 1</h1>'
    create_heading($value);
    create_description($value);
}

function wrapper2($value) {
    echo '<h1>This is the wrapper 2</h1>'
    create_heading($value);
    create_description($value);
}

function wrapper2($value) {
    echo '<h1>This is the wrapper 3</h1>'
    create_heading($value);
    create_description($value);
}


function render_things($options) {
    foreach ($options as $value) {
        switch($value['type']) {
            case "one":
                wrapper1($value);
                break;
            case "two":
                wrapper2($value);
            case "three":
                wrapper3($value);
        }
    }
}


render_things();

?>

所以有什么问题:

问题是如何根据数组中的tab-name动态回显选项卡中的这些值意味着我已经在tab-name中给出了第二个数组的值为2,所以如果我改变它应该在第二个选项卡中打印它应该分别将值打印到一个或三个.

我希望你们明白.

body {font-family: "Lato",sans-serif;}

/* Style the tab */
div.tab {
    overflow: hidden;
    border: 1px solid #ccc;
    background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
div.tab button {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 17px;
}

/* Change background color of buttons on hover */
div.tab button:hover {
    background-color: #ddd;
}

/* Create an active/current tablink class */
div.tab button.active {
    background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
    display: none;
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-top: none;
}
<div>
  <buttononclick="openCity(event,'tab1')" id="defaultOpen">tab 1</button>
  <buttononclick="openCity(event,'tab2')">tab 2</button>
  <buttononclick="openCity(event,'tab3')">Tab 3</button>
</div>

<div id="tab1">
  <h1>This is tab 1</h1>
</div>

<div id="tab2">
  <h1>This is tab 2</h1>
</div>

<div id="tab3">
  <h1>This is tab 3</h1>
</div>

<script>
function openCity(evt,cityName) {
    var i,tabcontent,tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active","");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " active";
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>

注意:我不想使用js来实现这些信息,所以如果可以使用PHP,请尽量避免使用js答案.

解决方法

你的PHP页面必须是这样的: –

<style>
body {font-family: "Lato",sans-serif;}

/* Style the tab */
div.tab {
    overflow: hidden;
    border: 1px solid #ccc;
    background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
div.tab button {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 17px;
}

/* Change background color of buttons on hover */
div.tab button:hover {
    background-color: #ddd;
}

/* Create an active/current tablink class */
div.tab button.active {
    background-color: #ccc;
}

.tabcontent {
    display: none;
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-top: none;
}
</style>
<?PHP
  // i assume that your page have this array available
 $options = array(

        array("name" => "Title","tab-name" => "Tab 3"

        )

    );

?>
<div>
<?PHP foreach($options as $option){?>
  <buttononclick='openCity(event,"<?PHP echo str_replace(" ","",$option["tab-name"]);?>")' id="defaultOpen"><?PHP echo $option['tab-name'];?></button>
<?PHP } ?>
</div>


<?PHP foreach ($options as $opti){?>
    <div id="<?PHP echo str_replace(' ','',$opti['tab-name']);?>">
      <?PHP foreach($opti as $key=>$val){?>
      <h1><?PHP echo $key;?> : <?PHP echo $val;?></h1>
      <?PHP } ?>
    </div>
<?PHP } ?>
<script>
function openCity(evt,"");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " active";
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>

输出: – http://prntscr.com/fydwix和http://prntscr.com/fydwnx和http://prntscr.com/fydwsg

c# – 什么是C中的数组^ T以及如何从数组中提取值?

c# – 什么是C中的数组^ T以及如何从数组中提取值?

我将一个C#对象数组传递给托管C DLL. C#类定义如下:

public class LatLonPointType
    {

        public double Lat;       // Latitude.
        public double Lon;       // Longitude.
    }

我将一个LatLonPointTypes数组传递给托管C DLL中的函数.通过反复试验,我发现我可以使用声明为的函数参数将其传递给C函数:

array <LatLonPointType^> ^polygonPoints

以下C代码将提取LatLonPointType ^类型的元素.

LatLonPointType ^a = polygonPoints[0];

我的问题是:

>我多年前使用过C,这似乎与参考声明相似. ^有一个很好的参考?
>在上面的示例中,如何将(LatLonPointType ^)转换为(LatLonPointType)值?

澄清:

如果我有:

LatLonPointType ^a = polygonPoints[i];

我怎么会得到a.Lat和a.Lon?

我会使用a-> Lat和a-> Lon?

解决方法

根据 this answer,这个帽子角色,也就是^,创建了一个托管指针,它将被垃圾收集,不一定是你.例如,如果您要使用new创建本机对象,它将如下所示:

Object* obj = new Object();

但是,如果您要使用托管指针,则语法将更改为:

MObject^ mobj = gcnew MObject();

目前,我找不到如何将托管指针转换为对象本身,但如果要将其转换为指向该对象的非托管指针,请参阅this answer.

编辑
要访问类的成员,例如Lon,您可以这样做:

//Get method
double i = polygonPoints[n]->Lon;
//Set method
polygonPoints[n]->Lon = number;

java – 如何从数组中选择一个值?

java – 如何从数组中选择一个值?

如何从数组中选择一个值?例如String [] ans = {“”,“ – ”,“/”,“*”};然后我想选择“”.

public static void main(String[] args) {
    String[] ans = {"+","-","/","*"};
    Random random = new Random();
    Scanner calcu = new Scanner(system.in);
    System.out.print("Enter First number: ");
    numOne = calcu.nextInt();
    System.out.print("Enter Second number: ");
    numTwo = calcu.nextInt();
    System.out.print("Choose an Operator to use");

}

解决方法

您可以将ans [0]用于“”等等.

ans[0] = "+";
ans[1] = "-";
ans[2] = "/";
ans[3] ="*";

在您的情况下,此代码将帮助您:

public static void main(String[] a) {

        String[] ans = {"+","*"};
        double result = 0;
        Scanner calcu = new Scanner(system.in);
        System.out.print("Enter First number: ");
        int numOne = calcu.nextInt();
        System.out.print("Enter Second number: ");
        int numTwo = calcu.nextInt();
        System.out.print("Choose an Operator to use");
        String oparation= calcu.next();

        if(oparation.equals(ans[0])){
           result = numOne + numTwo;
        }
        else if(oparation.equals(ans[1])){
            result = numOne - numTwo;
        }
        else if(oparation.equals(ans[2])){
            result = numOne / numTwo;

        } else if(oparation.equals(ans[3])){
            result = numOne * numTwo;
        }
        System.out.println("result is " + result);

   }

如果您想使用switch语句获得相同的结果:

public static void main(String[] a) {

        double result = 0;
        Scanner calcu = new Scanner(system.in);
        System.out.print("Enter First number: ");
        int numOne = calcu.nextInt();
        System.out.print("Enter Second number: ");
        int numTwo = calcu.nextInt();
        System.out.print("Choose an Operator to use");
        String oparation= calcu.next();

        switch(oparation){
            case "+" :
            result = numOne + numTwo;
            break;

            case "-" :
            result = numOne - numTwo;
            break;

            case "/" :
            result = numOne / numTwo;
            break;

            case "*" :
            result = numOne * numTwo;
            break;
        }
        System.out.println("result is " + result);

   }

但是,使用switch语句,如果要比较case ans [0]之类的变量:而不是case“*”,那么你可以使用enum.

javascript – 如何从origin选项卡中获取新打开的浏览器选项卡名称?

javascript – 如何从origin选项卡中获取新打开的浏览器选项卡名称?

我这样的代码在同一浏览器中从一个选项卡创建新选项卡到另一个选项卡.

function newTab()
{
    var form1 = document.createElement("form");
    form1.id = "newTab1"
    form1.method = "GET";
    form1.action = "domainname";  //My site address
    form1.target = "framename";   //browser tab name
    document.body.appendChild(form1);
    form1.submit();
}

上面的代码正常工作以创建新选项卡.当点击“MyNewTab”链接主页时

我再次尝试将主页切换到新打开的选项卡.此时需要从主页切换到新标签而无需重新加载.但重新加载了这个newtab内容.

如何获取选项卡名称并从单击“MyNewTab”链接获得新打开的选项卡的焦点?

最佳答案
您需要在javascript cookie中设置当前选定的选项卡,并始终在页面加载时读取此cookie并设置选项卡

你可以在newTab()函数中设置cookie:

function newTab()
{
    var form1 = document.createElement("form");
    form1.id = "newTab1"
    form1.method = "GET";
    form1.action = "domainname";  //My site address
    form1.target = "framename";   //browser tab name

    $.cookie("currentTab","framename");//set the selected tab name in cookie

    document.body.appendChild(form1);
    form1.submit();
}

然后,在页面加载事件:

var tabName=$.cookie("currentTab")//get the current tab name from cookie.
if(tabName==null){
tabName="default tab name"//at first time the cookie will be null,//so you need to assign a default value if the cookie is null
}

//set this tab as selected

jQuery UI选项卡转到选项卡中的特定div

jQuery UI选项卡转到选项卡中的特定div

我使用 JqueryUI设置了基本选项卡(简化为仅相关的两个选项卡)

<div id="tabs">
        <ul>
            <li><a href="#tabs-1">Home</a></li>
            <li><a href="#tabs-5">Benefits</a></li>

        </ul>
        <div id="tabs-1">
            <UCHome:UCHome runat="server" />
        </div>
        <div id="tabs-5">
            <UCBenefits:UCBenefits runat="server" />
        </div>
</div>

在tabs-1的usercontrol中(简化为相关代码)

<ahref="#benefitsmodularity">
     <span>Modularity</span>
     <asp:Image runat="server" ImageUrl="../Images/Benefits1.png"/></a> 
<ahref="#benefitsflexibility>
    <span>flexibility</span><asp:Image runat="server" ImageUrl="../Images/Benefits2.png" /></a>

在tabs-5的usercontrol中(再次简化)

<div>
    <div id="benefitsmodularity">
        <h2>
            (Modularity)</h2>
        <p>
            Hello
        </p>
    </div>
</div>
<div>
    <div id="benefitsflexibility">
        <h2>
            (flexibility)</h2>
        <p>
             World
        </p>
    </div>
</div>

homecontent类只是用于造型.

现在基本上,当用户点击tabs-1上的图像并且我希望它转到与图像相关的div时,我想从tabs-1重定向到tabs-5.例如,如果用户单击Benefits2.png,那么我希望它转到tabs-5并关注.

到目前为止,我已经在document.ready

var $tabs = $("#tabs").tabs();

$('.benefitc').click(function () { // bind click event to link
   $tabs.tabs('select',4); // switch to tab
   return false;
});

这让我正确选择了标签,但我无法弄清楚如何找到正确的div.请注意,所有点击都应该将我带到标签-5,即索引4.

任何帮助将非常感激.如果我对这个问题不够清楚,请告诉我.

解决方法

Aaaaaaaaaargh说代码猴子做了一些愚蠢的事.

这对我来说很愚蠢.

锚标签确实可以工作但是因为我正在使用

$('.benefitc').click(function () { // bind click event to link
   $tabs.tabs('select',4); // switch to tab
   return false;
});

返回false是停止事件传播,并且a标签的默认操作永远不会被触发.

所以改变它

return true;

达到了预期的效果.

我们今天的关于PHP:如何从数组中动态输入选项卡中的值?php动态创建数组的分享就到这里,谢谢您的阅读,如果想了解更多关于c# – 什么是C中的数组^ T以及如何从数组中提取值?、java – 如何从数组中选择一个值?、javascript – 如何从origin选项卡中获取新打开的浏览器选项卡名称?、jQuery UI选项卡转到选项卡中的特定div的相关信息,可以在本站进行搜索。

本文标签: