在元素被填充后立即对其触发Jquery
Trigger Jquery on an element immediately after it gets populated
我有一个文本区域,它在单击按钮后填充。
<textarea rows="4" cols="50" id="4321">
{{ data.classi}}
</textarea>
现在,我希望在它被填充之后发生一些事情。我尝试过onchange和其他一些选项,但它们只有在填充文本区域并更改其内容后才有效。我希望它能在从后端用json填充文本区域之后立即发生。如何做到这一点
$('#4321').on('change', function() {
alert( this.value ); // or $(this).val()
});
不起作用
我将整个代码粘贴在这里,以防对有帮助
<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
});
}
});
使用input
事件。(mdn(
$('#hello').on('input', function() {
console.log($(this)[0].value) // console logs the value of the textarea
});
$("#4321").change(function(){
alert("The text has been changed.");
});
这应该行得通。
相关文章:
- Firefox赢得了'不会显示我添加的jquery元素,但Chrome会显示
- 使用返回函数sinde.attr()jquery元素
- Wooccommerce所有JS和Jquery元素都未加载
- 追加JQuery元素和Angular
- 如何获取jQuery集合中的第k个元素..作为JQUERY元素
- 是否存在jQuery元素选择库的最小化版本
- 不能同时通过类和数字 ID 选择 jquery 元素
- 为什么jquery元素在ipad上没有响应
- Jquery元素用法
- 用于获取jQuery元素或值的方法
- 淡入淡出切换jquery元素
- 用于查找在 jQuery 元素集中具有特定类的元素的索引的单行代码
- 选择具有由 data() 设置的某个值的 JQuery 元素
- Jquery 元素的高级过滤
- 链接到另一个带有jQuery元素的页面
- jQuery:通过 .wrap() 添加到 DOM 的 jQuery 元素上的切换类
- 将字符串转换为 jquery 元素并将其追加到 DOM 中
- 与“click”事件一起存储的jQuery元素未按要求工作
- 在哈希数组中保存对 jquery 元素的引用
- 如何从核心JavaScript选择中获取jquery元素