javascript - 新内容后触发 jQuery
问题描述
我以为我以前解决了它,因为我没有收到错误,但结果是。在这个网站上,我有add content buttons
。系统在这些按钮中添加了一些文本,但我需要删除它们以匹配设计。
虽然我最初设法删除了文本,但它们在add content buttons
重新加载时再次出现。我尝试onlick
了事件委托,但到目前为止都没有工作。
jQuery(document).ready(function( $ ) {
// Application add/edit form remove text from buttons
$(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
$(document).on("click",'.paragraphs-buttons button', (function() {
$(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
})
);
});
解决方案
***已编辑:要删除文本内容,请尝试text()
在按钮内的 span 元素上使用函数。我还修复了代码语法,希望这次能正常工作。
jQuery(document).ready(function( $ ) {
// Application add/edit form remove text from buttons
$(".paragraphs-buttons button span").text("");
$(document).on("click",'.paragraphs-buttons button', function () {
$(".paragraphs-buttons button span").text("");
});
});
***旧答案我不太明白您要实现的目标,但如果您只想在点击时显示它。在单击事件之前删除$(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
,导致您在最初和单击发生时调用它两次。希望有帮助。
jQuery(document).ready(function( $ ) {
// Application add/edit form remove text from buttons
$(document).on("click",'.paragraphs-buttons button', (function() {
$(".paragraphs-buttons button").html("<span class='icon glyphicon glyphicon-plus' aria-hidden='true'></span>");
})
);
});
要删除内容,您可以使用$(selector).html("");
或$(selector).empty();
推荐阅读
- python - Python网页抓取数据操作
- excel - 在 Excel 中创建使用公式的用户表单
- php - 为什么 array(className,"privateFunctionName") 返回私有函数?
- javascript - 为什么我不能在回调中调用 useRef?
- python - AttributeError:将 ytickslabels 设置为摄氏度时,模块“matplotlib.pyplot”没有属性“set_ytickslabels”
- string - 如果 xldate < 0.00: TypeError: '<' 在 'str' 和 'float' 的实例之间不支持
- python - Python opencv无法加载灰色图像
- wysiwyg - 所见即所得来创建带注释的图像
- node.js - Node Js - 验证问题
- java - 在创建自定义查询方法时在 JPA 中创建查询异常