我还是个新手,我真的很难过。当选择第一个复选框时,如何将嵌入的YouTube视频回显到页面?请帮忙。感谢。
<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 :(得分: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>