我在从xml请求中选择表中的行时遇到问题。 请看下面的例子:
https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_database
我的网络很相似。是否可以使用JS功能让我在点击具有已定义类的行后更改背景?我想responseText不会返回类名。 目前我的JS函数可以在任何地方使用,但在DIV中不显示xml请求。
order.php:
// -that is a part from page that connect with sql base. it is what is return to main page and it works.[for example 3 squares with orderd detail]
while($num!=0) {
$row = $result->fetch_assoc();
echo '<div class="order"><p id="data">Date:'.$row['Whens'].'</p><p id="types">'.$row['Types'].' '.$row['Brand'].'</p><br><p id="whats">'.$row['Whats'].' </p><br> <p id="detai"> '.$row['Detai'] .'</p></div>';
$num--;
}
的index.php:
// -this is a part from main page where I get data from order.php - it works.
function showUser(id){
if (window.XMLHttpRequest) {
var xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
document.getElementById("order_t").innerHTML=this.responseText;
}
xmlhttp.open("GET","order.php?q="+id,true);
xmlhttp.send();
}
JS功能
// - I try use below to change background in div's with class="order" which I get from order.php. It does't work
$(".order").click(function(){
$(this).addClass("selected2").siblings().removeClass("selected2");
})