Jquery implements instance code that continuously adds values to the textarea by clicking a button

  • 2020-03-30 02:18:17
  • OfStack

The code is as follows:

<%@ page language="java" contentType="text/html; charset=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">
<script type="text/javascript" src="jquery-1.4.js"></script>
<script type="text/javascript">
        $("input[id^='buttonValidate']").click(function(){  //The function executes when you click on the input tag that contains 'buttonValidate' in all ids
         var btnVal=$.trim($(this).val());//Trim function to remove whitespace
         var str = $('#textareaValidate').val() + btnVal;//
<title>Insert title here</title>
<form  id="form1" name="form1" action="" method="post">
<table  id ="table1" class="base_table" cellspacing="0"  border="1" style="border-collapse: collapse">
  <td >

  <textarea cols="75" rows="5" id="textareaValidate"></textarea>
 <tr id="tr1">
  <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=" ) "/>

The above functions: click +, then add + to the textarea, click -, then add - to the textarea;

Related articles: