下面的鏈接代碼基本上是我用 json 文件中的食譜成分填充表格。我希望能夠單擊單個成分并在下面的 div 上顯示描述。嘗試只針對 td 元素而不使用類,嘗試將它們包裝在錨標記中,并在創建每個單元格時單擊每個單元格來構建 html, if (data['drinks'][0]['strIngredient' + i] !== null) { $("#recipe").append($('<tr>')) $("#recipe").append($('<td class ="ingredient"></td>').html(data['drinks'][0]['strIngredient' + i]).val(data['drinks'][0]['strIngredient' + i])); $("#recipe").append($('<td></td>').html(data['drinks'][0]['strMeasure' + i])); $("#recipe").append($('</tr>')); i++; } else iCheck = true; } $(".ingredient").click(function () { console.log('fired') })<div id="drinkDescription"> <p id="name" name="name"></p> <br> <table id="recipe" name="recipe"> </table> <br> <p id="description" name="description"> </p></div>
使用jquery獲取動態生成的表格中單元格的值
開滿天機
2023-09-28 10:21:19