<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
标签 javascript php jquery html css
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
我有三个按钮( Angular 色、部门、搜索)。单击 Angular 色时,div 将显示 Angular 色信息。 div代码是:
<div id="role_div" class="role" name="role" >
<?php
...
$sql = "select distinct role from hpc_user ;";
echo '<table>';
$sel=$conn->query($sql);
while($row=$sel->fetch(PDO::FETCH_NUM))
{
echo '<tr>';
echo '<td style="word-break:break-all;">'.$row[0].'</td>';
echo '</tr>';
}
echo '</table>';
?>
</div>`
点击部门按钮时,我希望整个div内容都是
<div id="role_div" class="role" name="role" >
<?php
$conn = new PDO('');
$conn->setAttribute(PDO::ATTR_ORACLE_NULLS, true);
$sql = "select distinct department from hpc_user ;";
echo '<table >';
$sel=$conn->query($sql);
while($row=$sel->fetch(PDO::FETCH_NUM))
{
echo '<tr>';
echo '<td style="word-break:break-all;">'.$row[0].'</td>';
echo '</tr>';
}
?>
</div>
我尝试使用
innerhtml.document.getElementById('role_div').innerHTML='<?php>....</php>'
,
但它不起作用。谁能帮助我?
最佳答案
您可以简单地将您的 Angular 色/部门数据放在两个隐藏的 div 中,然后您可以使用 Jquery 更改数据
您提到的另一个解决方案是您不能添加三个 div
HTML:
<div id="ajax_exchange"></div>
<input type="button" id="role" onclick="change_data(this.id);" value="role">
<input type="button" id="department" onclick="change_data(this.id);" value="department">
<input type="button" id="search" onclick="change_data(this.id);" value="search">
脚本:
<script type="text/javascript">
function change_data(id){
var data_to_fetch = $('#'+id).val();
$.ajax({
type: "post",
url: "<?php echo SFURI::SEFURL('index.php?itemtype=skus&layout=ajax_call',array('call'=>'ajax')); ?>",
dataType: 'html',
cache: false,
data: {get_this: data_to_fetch},
success: function(data){
$('#ajax_exchange').html("");
$('#ajax_exchange').html(data);
},
error: function(){
alert('Error while request..! try again');
}
});
}
</script>
ajax_call.php :
<?php
if(isset($_POST['get_this']) && $_POST['get_this']=="role"){
echo "role data";
// here you can put your role data to be sent to div
}
if(isset($_POST['get_this']) && $_POST['get_this']=="department"){
echo "department data";
// here you can put your department data to be sent to div
}
if(isset($_POST['get_this']) && $_POST['get_this']=="search"){
echo "search data";
// here you can put your search data to be sent to div
}
?>
希望对您有所帮助。
关于javascript - 单击不同的按钮时如何更改 div 内容.javascript php html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45137384/