简体   繁体   English

使用整个 DIV 作为带有 onchange 的按钮来刷新内容

[英]Use entire DIVs as buttons with onchange to refresh content

I don't know how to proceed and need your help!我不知道如何继续,需要您的帮助!

The goal is to use multiple <DIV> :s as a list, the list items are listed from AJAX/SQL.目标是使用多个<DIV> :s 作为列表,列表项从 AJAX/SQL 中列出。 When the user is clicking on one of the <DIV> :s it should change the "#main" <DIV> to view information about the specific <DIV> clicked in the list.当用户单击<DIV>之一时,它应该更改“#main” <DIV>以查看有关在列表中单击的特定<DIV>信息。 Hope you're following.希望你关注。

Right now I've found a script and got it working by using <form> , <select> and <option> as seen in the script below.现在我找到了一个脚本并通过使用<form><select><option>让它工作,如下面的脚本所示。

But instead of this drop down list, <select> I want the <DIV> in the list to be the link, as <a> or simular so that the content of the "#main" <div> is changed without the whole page is refreshing and without the .但不是这个下拉列表, <select>我希望列表中的<DIV>是链接,作为<a>或 simular,以便“#main” <div>的内容在没有整个页面的情况下被更改令人耳目一新,没有。

If you need any more info please let me know!如果您需要更多信息,请告诉我!

AJAX:阿贾克斯:

<script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>

HTML HTML

<form>
  <select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="1">Peter Griffin</option>
  <option value="2">Lois Griffin</option>
  <option value="3">Joseph Swanson</option>
  <option value="4">Glenn Quagmire</option>
  </select>
</form>

<div id="txtHint"><b>Person info will be listed here...</b></div>

使用已发布但已删除的此答案,因此如果有人遇到相同的问题,这就是要走的路: ANSWER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM