2013-07-02 83 views
0

我仍然是一个新手,我真的很难在这个。当第一个复选框被选中时,如何能够将嵌入的YouTube视频回显到页面?请帮忙。谢谢。回声iframe里面的值

<form action="" method="post"> 
    <label><input type="checkbox" name="check_list[]" value="<?php echo "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/TnxUOdAhAdk\" frameborder=\"0\" allowfullscreen></iframe>"; ?>">Video1</label> 
    <label><input type="checkbox" name="check_list[]" value="value 2">Video2</label> 
    <label><input type="checkbox" name="check_list[]" value="value 3">Video3</label> 
    <input type="submit" /> 
</form> 


<?php 
if(!empty($_POST['check_list'])) { 
    foreach($_POST['check_list'] as $check) { 
     echo $check; 
    } 
} 
?> 

回答

0

我推荐你使用javascript/jquery而不是php,因为你已经知道你的youtube链接。 This link will give you more info about this

总之这里是一个PHP代码,可以帮助你:

<html> 
<head> 
</head> 
<body> 
    <form action='index.php' method='post'> 
     <input type='checkbox' name='video1' value='true'/>Show Video1 
     <br/> 
     <input type='checkbox' name='video2' value='true'/>Show Video2 
     <br/> 
     <input type='checkbox' name='video3' value='true'/>Show Video3 
     <br/> 
     <input type='submit' value='Show Videos'/> 
    </form> 

    <?php 
    if (isset($_POST['video1'])) { 
     echo "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/TnxUOdAhAdk\" frameborder=\"0\" allowfullscreen></iframe>"; 
     echo "<br/>"; 
     echo "<br/>"; 
    } 
    if (isset($_POST['video2'])) { 
     echo "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/2mKxsC2oi5s\" frameborder=\"0\" allowfullscreen></iframe>"; 
     echo "<br/>"; 
     echo "<br/>"; 
    } 
    if (isset($_POST['video3'])) { 
     echo "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/tC2fjzWIM-Y\" frameborder=\"0\" allowfullscreen></iframe>"; 
     echo "<br/>"; 
     echo "<br/>"; 
    } 
    ?> 
</body> 
</html>