簡體   English   中英

如何將數據從一個html頁面動態添加到另一個html頁面中的列表

[英]how to dynamically add data from one html page to a list in another

我在html頁面上有一個字符串項列表,如下所示 -

<h1><b>Subject Groups</b></h1>
        <div id="listContainer">
            <div class="listControl">
            </div>
            <ul id="expList">
                <li>
                    Maths 
                    <ul>
                        <li>
                            John Smith       
                        </li>
                        <li>
                            Jane Smith
                        </li>
                        <li>
                            Elvis Presley
                        </li>
                    </ul>
                </li>
                <li>
                    Science 
                    <ul>
                    <li>
                    Jane Smith
                    </li>
                    <li>
                    Kate Smith
                    </li>
                    </ul>
                </li>
                <li>
                    Literature
                    <ul>
                        <li>
                            Kate Smith
                        </li>
                        <li>
                            Tom Hanks
                        </li>
                    </ul>
                </li>
                <li>
                <a href = "JavaScript:newPopup('new.html');"<b>New Student..</b></a>
                </li>
            </ul>

在列表的末尾,有一個彈出窗體的鏈接,允許您輸入新學生並通過復選框選擇該人正在學習的科目 -

<form action="" style= "font-size: 16pt">

<h3> First Name: </h3>

    <div class="input-group">
      <input type="text" class="form-control">

      <h3> Last Name: </h3>

    <div class="input-group">
      <input type="text" class="form-control">


      <h3> Email Address: </h3>

    <div class="input-group">
      <input type="text" size="70" class="form-control">

    </div><!-- /input-group -->

    <h3> Select the subjects that this student will study: </h3>


<input type="checkbox" name="Maths" value="Maths"> &nbsp Maths<br>
<input type="checkbox" name="Science" value="Science"> &nbsp Science<br>
<input type="checkbox" name="Literature" value="Literature"> &nbsp Literature>
<input type="button" class="btn btn-lg btn-primary btn-block" value="Submit" />
</form>

我的問題是 - 如何使用提交按鈕的onClick事件獲取新創建的學生的名字和姓氏,並將它們添加到我的列表中的相應主題類別? 沒有數據庫背后的可能嗎?

我認為使用jquery很容易...只需給每個主題一個ID,例如<li id="Maths">然后當用戶提交表單時獲取復選框值並使用.append添加到列表中,例如

> $(chekBoxValue).append("<li>"+name+'</li>');

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM