在填充后立即触发元素上的Jquery

时间:2016-10-27 12:04:59

标签: javascript jquery html

我有一个文本区域,点击按钮后会填充。

$('#4321').on('change', function() {
  alert( this.value ); // or $(this).val()
});  

现在我想在填充后发生一些事情。我已尝试过onchange和其他一些选项,但它们仅在填充textarea并且我们更改其内容后才能工作。  我希望它在textarea从后端填充json之后立即发生。怎么做呢

<html ng-app="myApp">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="js/main.js"></script>
   <script src="jquery.json-view.js"></script>
  <link href="jquery.json-view.css" rel="stylesheet"></link>

    <style>
        table, th , td  {
          border: 1px solid grey;
          border-collapse: collapse;
          padding: 5px;
        }
        table tr:nth-child(odd) {
          background-color: #f1f1f1;
        }
        table tr:nth-child(even) {
          background-color: #ffffff;
        }
    </style>
  </head>
  <body ng-controller="DebugController">
    
    <div>
      <input type="text" ng-model="query" placeholder="Search Query">
      <input type="text" ng-model="pog"  placeholder="Enter No of POGs">
      <button ng-click="onSearch()" class="button" id ="abcd">Search</button>
    </div>
    <textarea rows="4" cols="50" id="abc">
 	 {{ data.classi}}
   </textarea>
    <div>
        <h4>Parameters</h4>
         <table>
          <tr ng-repeat="x in data.p ">
            <td>{{ x[0] }}</td>
            <td>{{ x[1] }}</td>
          </tr>
        </table>
    </div>
    <div>
        <h4>Classifier Scores</h4>
        <table>
          <tr>
            <th>Category URL</th>
            <th>Additive Boost</th>
          </tr>
          <tr ng-repeat="x in data.classifier">
            <td>{{ x[0] }}</td>
            <td>{{ x[1] }}</td>
          </tr>
        </table>
    </div>
    <div>
        <h4>Product Groups (POGs)</h4>
        <table>
          <tr>
            <th>Id</th>
            <th>Details</th>
            <th>Score</th>
            <th>HPSA Score</th>
            <th>BF Score</th>
            <th>Word Match</th>
            <th>Classifier Score</th>
            <th>QUL Score</th>
          </tr>
          <tr ng-repeat="x in data.items | limitTo: limit " >
            <td><a href="{{ x.get }}">{{ x.id }}</td>
            <td>
                <p><b>{{ x.name[0] }}</b></p>
                <p><u>Brand</u>: {{ x.Brand }}; <u>Category URL</u>: {{ x.mlnURL }};<u>Price</u>: Rs {{x.Price}} </p>
            </td>
            <td>
                <p><a href="{{x.explain}}"><b>{{ x.score }}</b></a></p>
                Classifier Score: {{ x.cscore }} <br>
                Document Score: {{ x.sscore }} </p>
            </td>
            <td>
                <p><b> {{ x.hpsaScore_default }} </b></p>
            </td>
            <td>
                <p><b> {{ x.bf_value }} </b></p>
            </td>
            <td>
                
            </td>
            <td>
                <p> <b> {{ x.cscore }} </b></p>
            </td>
            <td>
                
            </td>
          </tr>
        </table>
    </div>
    <div>
        <h4>Solr Query</h4>
        <p>{{ data.query }}</p>
    </div>
<script>
var pog;
$(function() { 
 $('#abc').on('input', function() {
    alert("hi");
});
	});

		
</script>
  </body>
</html>

这不起作用

我在这里粘贴整个代码,以防它有帮助

	
var app = angular.module('myApp', []);

app.controller('DebugController', function($scope, $http) {
  $scope.onSearch = function () {
    $scope.data = {}
    number = $scope.pog
    $scope.limit = number
    $http.get('/search?q=' + $scope.query)
       .then(function(response) {
            console.log(response)
            params = []
	    urls = []
            for (p in response.data.params) {
                params.push([p, response.data.params[p]])
            }	
	    for (i in response.data.bf_value) { 
		for(j in response.data.bf_value[i]) {
			}
		
   	  }
	    for( t in response.data.items ) {	
		p =""
		for ( s in response.data.bf_value ) { 
			p+=response.data.bf_value[s][t]
			
		}
		response.data.items[t].bf_value = p
		}
	    console.log(response.data.bf_value);
            $scope.data = response.data
	    $scope.data.classi = response.data.classify	
            $scope.data.p = params
            $scope.data.u = urls 

        });
   
  }
});

页面的控制器

{{1}}

2 个答案:

答案 0 :(得分:0)

使用input事件。 (mdn

$('#hello').on('input', function() {
    console.log($(this)[0].value) // console logs the value of the textarea
});

答案 1 :(得分:-1)

 $("#4321").change(function(){
        alert("The text has been changed.");
    });

这应该有用。