jQuery實現在列表的首行添加資料

來源:互聯網
上載者:User

jQuery實現在列表的首行添加資料

   這篇文章主要介紹了jQuery實現在列表的首行添加資料的方法,十分的簡單,有需要的小夥伴可以參考下。

  jQuery中可以通過append在列表的最後添加資料,也可以通過prepend在列表的最前面添加資料

  方法很簡單:

  複製代碼 代碼如下:

  jQuery('#comment_list').prepend('

  • hello www.jb51.net

');

 

  另外附上jquery實現連續向textarea文本域添加資料的代碼。

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

<%@ page language="java" contenttype="text/html; charset=gbk" pageencoding="gbk"%>

<%@ include file="/pages/common/taglibs.jsp"%>

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">

<html>

<head>

<script type="text/javascript" src="jquery-1.4.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$("input[id^='buttonvalidate']").click(function(){ //當點擊所有的id中包含'buttonvalidate'的input標籤時,執行函數

var btnval=$.trim($(this).val());//trim函數,去掉空格

var str = $('#textareavalidate').val() + btnval;//

$('#textareavalidate').val(str);//

});

});

</script>

<title>insert title here</title>

</head>

<body>

<form id="form1" name="form1" action="" method="post">

<table id ="table1" class="base_table" cellspacing="0" border="1" style="border-collapse: collapse">

<tr>

<td>

<textarea cols="75" rows="5" id="textareavalidate"></textarea>

</td>

</tr>

<tr id="tr1">

<td>

<input id="buttonvalidate1" type="button" value=" + "/>

<input id="buttonvalidate2" type="button" value=" - "/>

<input id="buttonvalidate3" type="button" value=" * "/>

<input id="buttonvalidate4" type="button" value=" / "/>

<input id="buttonvalidate5" type="button" value=" ! "/>

<input id="buttonvalidate6" type="button" value=" = "/>

<input id="buttonvalidate7" type="button" value=" < "/>

<input id="buttonvalidate8" type="button" value=" > "/>

<input id="buttonvalidate9" type="button" value=" & "/>

<input id="buttonvalidate10" type="button" value=" | "/>

<input id="buttonvalidate11" type="button" value=" ( "/>

<input id="buttonvalidate12" type="button" value=" ) "/>

</td>

</tr>

</table>

</form>

</body>

</html>

  以上實現的功能:點擊+,則把+添加到textarea中,點擊-,則把-添加到textarea中;

  以上所述就是本文的全部內容了,希望大家能夠喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.