如何使用PHP/Javascript生成带有按钮的动态div?
大家好,我想用按钮生成这个div如何使用PHP/Javascript生成带有按钮的动态div?,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,大家好,我想用按钮生成这个divquestion,但问题是这个div是动态的。这是我的密码。按钮还没有javascript代码,因为我还不知道怎么做 surveycontent.php <div id="question"> </div> <div class="col-md-2"> <input type="submit" name="addsection" class="btn b
question
,但问题是这个div是动态的。这是我的密码。按钮还没有javascript代码,因为我还不知道怎么做
surveycontent.php
<div id="question">
</div>
<div class="col-md-2">
<input type="submit" name="addsection" class="btn btn-default" value="Add Section" id="addsection" />
</div>
<script>
function load_questions(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php??main=1&subcategory="+document.getElementById("subcategorydd").value +"&cnt="+document.getElementById("q_num").value,false);
xmlhttp.send(null);
document.getElementById("question").innerHTML=xmlhttp.responseText;
}
</script>
<?php
$con = mysqli_connect("server","username","","password") or die ("Cannot connect to the database!");
$subcat=isset($_GET["subcategory"])?$_GET["subcategory"]:"";
if($subcat !="") {
$query=mysqli_query($con, "SELECT * FROM question WHERE question_subcat = $subcat ");
echo "<select>";
while($row=mysqli_fetch_array($query))
{
echo "<option value='$row[question_id] selected'>" ; echo $row["questiontitle"]; echo "</option>";
}
echo "</select>";
}
?>
函数加载_问题(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open(“GET”、“ajax.php??main=1&subcategory=“+document.getElementById(“subcategory dd”).value+”&cnt=“+document.getElementById(“q_num”)。value,false);
xmlhttp.send(空);
document.getElementById(“问题”).innerHTML=xmlhttp.responseText;
}
php这是surveycontent.php中div id后面的代码
<div id="question">
</div>
<div class="col-md-2">
<input type="submit" name="addsection" class="btn btn-default" value="Add Section" id="addsection" />
</div>
<script>
function load_questions(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php??main=1&subcategory="+document.getElementById("subcategorydd").value +"&cnt="+document.getElementById("q_num").value,false);
xmlhttp.send(null);
document.getElementById("question").innerHTML=xmlhttp.responseText;
}
</script>
<?php
$con = mysqli_connect("server","username","","password") or die ("Cannot connect to the database!");
$subcat=isset($_GET["subcategory"])?$_GET["subcategory"]:"";
if($subcat !="") {
$query=mysqli_query($con, "SELECT * FROM question WHERE question_subcat = $subcat ");
echo "<select>";
while($row=mysqli_fetch_array($query))
{
echo "<option value='$row[question_id] selected'>" ; echo $row["questiontitle"]; echo "</option>";
}
echo "</select>";
}
?>
在何处调用函数加载问题
?能否添加代码段。。