doudao8283 2012-07-09 15:21
浏览 119
已采纳

PHP。 如何动态更改HTML选择操作的页面内容?

I have this code:

page.php:

<?php

include ('include.php');

echo = '
<li>
    <select name="selector" class="letter">
        <option value="a" selected="selected">$a</option>
        <option value="b">$b</option>
    </select>
</li>
';

echo = '
<li>
    <select name="a-numbers" class="number a-numbers">
        <option value="$a[1][1]">$a[1][2]</option>
        <option value="$a[2][1]">$a[2][2]</option>
    </select>
    <select name="b-numbers" class="number b-numbers">
        <option value="$b[1][1]">$b[1][2]</option>
        <option value="$b[2][1]">$b[2][2]</option>
    </select>
</li>
';

?>

&

include.php:

<?php

$array = array(
    "a" => array(
        "1" => array("aaa1-value","aaa1-text"),     
            "2" => array("aaa2-value","aaa2-text")      
        ),  
        "b" => array(
            "1" => array("bbb1-value","bbb1-text"),     
            "2" => array("bbb2-value","bbb2-text")      
        )   
    )
);

?>

If .letter>a is selected, .a-numbers list should be echo-printed; and if .letter>b is selected, .a-numbers list should be removed and .b-numbers should be printed.

Of course, I can create this scenario with JS and CSS display:none; however, I can't use display:none here. So I have to remove elements from DOM, but I can't.

Thanks for your attention.

  • 写回答

2条回答 默认 最新

  • doutany76678 2012-07-09 15:28
    关注

    PHP cannot dynamically do any of this on it's own. You will need to either use AJAX, which will actually send a request/response back to the server to populate the div.

    Or, you will need to load all possible content with the initial request/response and use javascript to dynamically show/hide the divs in question.

    You mention in your question that you cannot use display:none, so you may want to look into making an asychronous call back the webserver to populate the element.

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题