如何使用jquery动态地向表中添加值?

时间:2017-12-12 02:19:37

标签: javascript jquery

我实现了创建表的函数,并在输入当前数据时添加了一个值。

这是代码:
HTML:

from selenium import webdriver
import time

stocks = ['RKN','MG','GTE','IMO','REI.UN','RY']
dt = []

url = 'https://app.tmxmoney.com/research/insidertradesummaries?locale=EN'

driver = webdriver.Firefox()
driver.get(url)

search = driver.find_element_by_xpath('//ul[@class="nav nav-pills"]/li[3]')
search.click()

stock_form = driver.find_element_by_name('text')

for stock in stocks:
    stock_form.clear()
    stock_form.send_keys(stock)
    stock_form.submit()
    data = driver.find_element_by_xpath('//div[@class="insider-trades-symbol-search-container"]/div[@class="ng-binding"]')
    a = data.text.split('\n')
    **time.sleep(1)**
    if len(a) > 1:
        dt.append(a[-1].split())
    else:
        dt.append([])

driver.close()

JS:

<div class="firstDate" style="margin-left: 35px;" data-role="fieldcontain">
    <input type="date" id="firstDate" onchange="checkTodayDate(this)" name="ri_startDate">
</div>

<div class="secondDate" data-role="fieldcontain">
    <input type="date" id="secondDate" onchange="checkTodayDate2(this)" name="ri_endDate">                  
</div>

<div class="hospitalTime" style="margin-top: 12px;/* padding: 3px; */margn-left: 5px;margin-left: 5px;margin-right: 5px;" data-role="fieldcontain">
    <input type="text" style="width: 195px;" name="ri_chozyinTime"  id="ri_chozyinTime">                    
</div>

<div class="hospitalTime" style="margin-top: 12px;/* padding: 3px; */margn-left: 5px;margin-left: 5px;margin-right: 5px;" data-role="fieldcontain">
    <input type="text" style="width: 195px;" name="ri_zaezyinTime" id="ri_zaezyinTime">                 
</div>

<div class="table-responsive dataZone" style="margin-top:30px">
    <table class="table" data-role="table" id="table-column-toggle" data-mode="columntoggle" style="display:none">
        <thead>
            <tr>
                <th data-priority="1">First Date</th>
                <th data-priority="2">Second Date</th>
                <th data-priority="3">First Medical</th>
                <th data-priority="4">Second Medical</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
        </table>
        <div style="display:none" class="submitGo">
            <input class="btn btn-default btn-sm" value="Submit" type="submit">
        </div>
</div>

如果输入一个值并按“添加”按钮,则会实现该行以创建一行。

我将来想做的是,

如果function AddScore() { $('#table-column-toggle').show(); $('.submitGo').show(); var jqTableBody = $('#table-column-toggle tbody'); var sTRTemplate = '<tr>' + ' <td>{firstDate}</td>' + ' <td>{secondDate}</td>' + ' <td>{chozyin}</td>' + ' <td>{zaezyin}</td>' + '</tr>'; var sTRAppend = sTRTemplate; $('div[data-role="fieldcontain"] > input').each(function(){ switch(this.id) { case 'firstDate' : sTRAppend = sTRAppend.replace('{firstDate}', this.value); break; case 'secondDate' : sTRAppend = sTRAppend.replace('{secondDate}', this.value); break; case 'ri_chozyinTime' : sTRAppend = sTRAppend.replace('{chozyin}', this.value); break; case 'ri_zaezyinTime' : sTRAppend = sTRAppend.replace('{zaezyin}', this.value); break; } }); firstDate值相同,如果输入值并单击“添加”按钮,则不会创建新行。

显示下图。

enter image description here

如何实施我想要实施的内容?

如果你能告诉我如何,我将不胜感激。

0 个答案:

没有答案