选择框的PHP onchange事件

时间:2017-03-09 07:14:33

标签: php onchange

我是PHP和这个社区的新手 我试图在php select中使用onchange函数 但似乎没有用 我搜索了解决方案,但基本上都是JS和值的URL,但我的值将用于php for循环 不想在URL中获取参数 请帮忙

echo "<select onchange='myFunction(this.value)'>";
echo "<option value=''>select your number</option>";
echo "<option value='5'>5</option>";
echo "<option value='10'>10</option>";
echo "<option value='15'>15</option>";
echo "</select>";
//////////////////////////////////////////////////////
function myFunction($numbers){
    for($count=0;$count<$numbers;$count++)
        echo $count;
}
顺便说一下,for循环内部包含一些MySQL,这就是为什么我使用PHP

2 个答案:

答案 0 :(得分:1)

&#13;
&#13;
    $('.search-submit').click(function (e) {
        e.preventDefault();

        var searchbox = $('.search-box');

        if(searchbox.hasClass('expanded-search-box'))
        {
            // close the form
            searchbox.removeClass('expanded-search-box');
        }

        else {
            // open the form
            searchbox.addClass('expanded-search-box');
        }

    });
&#13;
        .form-container{
            width: 600px;
            margin: 0 auto;
            border: 1px solid #000;
            padding: 33px 14px;
        }

        .form-container:after{
            content: '';
            display: block;
            clear: both;
        }

        form{
            position: relative;
            float: right;
        }

        .search-box{
            top: 0;
            right: 0;
            width: 90px;
            transition: width 0.3s ease-out;
            padding: 10px 0px;
            padding-left: 10px;
            outline: none;
        }

        .search-submit{
            position: absolute;
            width: 110px;
            top: 0;
            right: 0;
            padding: 10px 0px;
        }

        .expanded-search-box{
            width: 500px;
        }
&#13;
&#13;
&#13;

希望这有帮助!

答案 1 :(得分:-1)

我认为你可以像这样编码

<?php 
header('contact-type:text/javascript;charset=utf-8');
echo "<select onchange='myFunction(this.value)'>";
echo "<option value=''>select your number</option>";
echo "<option value='5'>5</option>";
echo "<option value='10'>10</option>";
echo "<option value='15'>15</option>";
echo "</select>";
?>
<script>
function myFunction($numbers){
    for($count=0;$count<$numbers;$count++)
        echo $count;
}
</script>