[英]Javascript not running until refreshing the page
My code just grabs trello board name, put it into curly brackets, and insert it into text area when clicking "add a card". 我的代码只是获取trello板的名称,将其放在大括号中,然后在单击“添加卡”时将其插入文本区域。 However, it doesn't insert the board name into text area unless I refresh the page.
但是,除非刷新页面,否则它不会将面板名称插入文本区域。
Here's my code: 这是我的代码:
$(document).ready(function() {
$('.js-open-card-composer').click(function() {
setTimeout(addTitle, 100);
});
});
function addTitle() {
var boardName;
boardName = document.title.replace(' | Trello', '');
$('.list-card-composer-textarea').each(function() {
$(this).val('{' + boardName + '}');
});
}
I've already tried $(window).load. 我已经尝试过$(window).load。
Thanks in advance 提前致谢
You should bind to the body not to the element incase it doesnt exist 如果不存在,则应绑定到主体而不是元素
$('body').on('click', '.js-open-card-composer',function() {
//probably don't need the timeout anymore
setTimeout(addTitle, 100);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.