.children(“:第一个children”)-ajax-多个第一个children
.children(":first-child") - ajax - multiple first children?
我有一个简单但奇怪的问题——当我选择.children(":first-child")
时,会给出多个结果,一个又一个警报。
// ...
$.post(ajaxurl, data, function (response) {
//alert(response);
tinymce.get('geqqo-editor-new').setContent('');
$('#geqqo-modal-new').modal('hide');
$('#geqqo-modal-new').on('hidden.bs.modal', function (e) {
$('#timeline').prepend(response);
var new_status = $('#timeline').children(":first-child").attr("id");
alert(new_status);
});
// ...
如何只选择第一个孩子(即最近附加的孩子),而不是像现在这样选择多个孩子。
尝试使用一个方法而不是on方法,使用:first
而不是:first-child
$('#geqqo-modal-new').one('hidden.bs.modal', function (e) {
$('#timeline').prepend(response);
var new_status = $('#timeline').children(":first").attr("id");
alert(new_status);
});
使用
var new_status = $('#timeline').children(":first").attr("id");
虽然:first
只匹配单个元素,但:first-child
选择器可以匹配多个元素:每个父元素一个。
此外,您还将同一事件绑定到一个元素两次。你应该使用。.one()
方法代替.on
$('#geqqo-modal-new').one('hidden.bs.modal', function (e) {
/*code here*/
}
.one()
将处理程序附加到元素的事件。每个元素每个事件类型最多执行一次处理程序。
相关文章:
- 而循环只设置php中输入字段中的第一个值
- 错误:$injector:modulerr模块错误(我的第一个SPA应用程序)
- IE11中的第二个调用取消了第一个Fetch API调用
- Javascript XMLHttpRequest——只有第一个POST请求有效
- 使用javascript或angularjs特定过滤器搜索字符串中第一个img标记的json值
- 将OnClick函数设置为<ul>,最后一个ul是擦除第一个ul-s
- RxJS油门行为;立即获取第一个值
- Angular UI网格:如何通过第一个UI网格中的按钮使第二个UI网格可见
- 选择多个实例中的第一个
- 如何在调用下一个请求之前完成第一个Ajax Get请求
- Lodash:返回对象的第一个键,该对象的值(即数组)中有一个给定的元素(即字符串)
- 看起来第一个console.log是'It’不太对
- 与杜兰达尔合作的第一个JavaScript项目.尝试从第三方 API 获取数据
- 节点发布错误对象的第一个“属性”
- Javascript:表单验证getElementById仅返回第一个id元素
- 仅将 CSS 规则应用于
中的第一个 ,而不分配类/ID - JS在隐藏未定义的值后仅从数组中返回第一个id的值
- 高图表,检测点是否在堆栈中的第一个
- json结果显示第一个值
- .children(“:第一个children”)-ajax-多个第一个children