[英]Is this possible in JQUERY? val() and text()
在JQUERY的一個內聯代碼中是否有可能?
<table>
<tr>
<!-- Ex. this is the td:nth-child(10) -->
<td>
<input type="hidden" value=""/>
<p> </p>
</td>
</tr>
</table>
// I'd like to ouput a same value in td 10th cell in one liner code..
$(this).children('td:nth-child(10)').text(data[0]).val(date[0]);
任何幫助謝謝?
老答案:是的,可以。 但這沒有任何意義,因為td
不使用val 。
.val()方法主要用於獲取表單元素的值,例如輸入,選擇和文本區域。 當集合中的第一個元素為select-multiple(即具有設置了multi屬性的select元素)時,它將返回一個包含每個選定選項的值的數組;如果未選擇任何選項,則返回null。 當在空集合上調用時,它返回undefined。
下面是一個片段,其中首先使用text()
,然后使用val()
。 但是val()
不會影響任何東西。
更新 :使用新的HTML,可以設置P
,然后設置input
。
changeIt = function(){ $('td:nth-child(2) p').text('foo').closest('td').find('input').val('bar'); };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <td> <input type="hidden" value="inital1"/> <p>1</p> </td> <td> <input type="hidden" value="inital2"/> <p>2</p> </td> <td> <input type="hidden" value="inital3"/> <p>3</p> </td> <td> <input type="hidden" value="inital4"/> <p>4</p> </td> </tr> </table> <button onclick="changeIt()">Click two change 2</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.