亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

javascript 從表中獲取/存儲數據

javascript 從表中獲取/存儲數據

侃侃無極 2023-12-19 16:03:50
我試圖在單擊按鈕后根據 id 捕獲數據(例如存儲它們),以便使用它來將所需的 id 插入到數據庫中。編寫的 js 沒有按預期工作,有什么想法缺少什么嗎?謝謝你的支持。    <script>    function goo() {    idprod=$("#idprod").val();    nprod=$("#nprod").val();    lastprod=$("#lastprod").val();    solarprod=$("#solarprod").val();    locprod=$("#locprod").val()  }</script><form name="goo" method="post"> <table border="1">  <tr>    <th>ID</th>    <th>Name</th>    <th>Lastname</th>    <th>WK_Solar</th>    <th>Location</th>    <th>Save</th>  </tr>    <tr>      <td id="idprod">P1</td>    <td id="nprod">James</td>    <td id="lastprod">Lee</td>    <td id="solarprod">$1555</td>    <td id="locprod">Queens</td>    <td><input type="hidden" name="active" value="active"><input type="submit" name="submit" value="goo"></td>  </tr>  <tr>      <td id="idprod">P2</td>    <td id="nprod">Marc</td>    <td id="lastprod">Hoobs</td>    <td id="solarprod">$955</td>    <td id="locprod">Bronx</td>    <td><input type="hidden" name="active" value="active"><input type="submit" name="submit" value="goo"></td>  </tr></table></form>
查看完整描述

1 回答

?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

1- 您正在使用 val,它是屬性 Value。您應該使用 html() 或 text() 來獲取值。


2-您有兩行,您應該瀏覽這兩行并從每行獲取數據


 function goo() {

    var firstRow = $(".test tbody tr").last();

    idprod=firstRow.find("#idprod").html();

    nprod=firstRow.find("#nprod").html();

    lastprod=firstRow.find("#lastprod").html();

    solarprod=firstRow.find("#solarprod").html();

    locprod=firstRow.find("#locprod").html()

    

    console.log(idprod)

  }

  $(document).ready(function(){

  

   goo();

  });

 

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form name="goo" method="post"> 

<table border="1" class="test">

<thead>

  <tr>

    <th>ID</th>

    <th>Name</th>

    <th>Lastname</th>

    <th>WK_Solar</th>

    <th>Location</th>

    <th>Save</th>

  </tr>

</thead>

    <tr>  

    <td id="idprod">P1</td>

    <td id="nprod">James</td>

    <td id="lastprod">Lee</td>

    <td id="solarprod">$1555</td>

    <td id="locprod">Queens</td>

    <td><input type="hidden" name="active" value="active"><input type="submit" name="submit" value="goo"></td>

  </tr>

  <tr>  

    <td id="idprod">P2</td>

    <td id="nprod">Marc</td>

    <td id="lastprod">Hoobs</td>

    <td id="solarprod">$955</td>

    <td id="locprod">Bronx</td>

    <td><input type="hidden" name="active" value="active"><input type="submit" name="submit" value="goo"></td>

  </tr>

</table>

</form>


查看完整回答
反對 回復 2023-12-19
  • 1 回答
  • 0 關注
  • 164 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號