我想获取按钮的父节点,该节点应该是def destroy
@workout = Workout.friendly.find(params[:workout_id])
exercise = Exercise.find(params[:id])
if exercise.destroy
flash[:notice] = "Exercise was deleted successfully."
redirect_to [@workout]
else
flash[:alert] = "Exercise couldn't be deleted. Try again."
redirect_to [@workout]
end
end
元素,而是获取td
元素。是什么造成的?我想只使用JavaScript,不使用jQuery。
这是我的代码:
body
答案 0 :(得分:4)
问题是您的{h}无法将<tr>
放入<table>
。然后,浏览器拒绝它并遇到没有有效父级的<td>
,然后遇到没有有效父级的<button>
,最后会遇到<body>
。
当您提供无效的html标记时,会出现意外结果。
将<tr>
换入<table></table>
,也可以<tbody>
内的<thead>
,<tfoot>
或<table>
请注意,某些标记,特别是表标记对于允许父级和子级的内容非常具体。
的 DEMO 强>