我需要访问哪个列的样式显示无
我采用这样的表格列:
<% ResultSet rs = st.executeQuery(query); %>
<% while(rs.next()) { %>
<tbody>
<tr>
<td><%=rs.getString(5)%></td>
<td style="display:none;"><%=rs.getString(6)%></td>
<td style="display:none;" id="name"><%=rs.getString(7)%></td>
<td style="display:none;"><%=rs.getString(8)%></td>
</tr>
<% } %>
使用Javascript:
<script type="text/javascript">
function printIt(){
var name=document.getElementById("name").value;
alert(name);
}
</script>
<body><input type="submit" value="Get Value" onclick="printIt();"/></body>
当我点击按钮时,它会在Undefined
中显示提醒我如何访问此
答案 0 :(得分:1)
而不是Element.value
您应该使用Element.innerHTML:
代码示例:
function printIt() {
var name = document.getElementById('name').innerHTML;
console.log(name);
}
<table>
<tr>
<td><a href="WorkAreaNew.jsp?id=1">Dynamic text 1</a></td>
<td>Dynamic text 2</td>
<td style="display:none;">Dynamic text 3</td>
<td style="display:none;" id="name">Dynamic text 4</td>
<td style="display:none;">Dynamic text 5</td>
</tr>
</table>
<input type="submit" value="Get Value" onclick="printIt();"/>
答案 1 :(得分:0)
我认为您需要所有td
style="display:none"
function printIt() {
$("td[style*='display:none']").each(function(){
console.log($(this).text());
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td style="display:none;">Some string here...</td>
</tr>
<tr>
<td style="display:none;">Some string here...123</td>
</tr>
</table>
<input type="submit" value="Get Value" onclick="printIt();"/>