我正试图在另一个函数中调用随机函数。例如,我想这样做<input type="image" id="ibCTC" src="images/ibCTC.png" class="js-textareacopybtn" />
<textarea class="js-copytextarea">Hello I'm some text</textarea>
function bindEvent(el, eventName, eventHandler) {
if (el.addEventListener){
el.addEventListener(eventName, eventHandler, false);
} else if (el.attachEvent){
el.attachEvent('on'+eventName, eventHandler);
}
}
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
bindEvent(copyTextareaBtn, 'click',function(event) {
var copyTextarea = document.querySelector('.js-copytextarea');
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
alert('Copying text command was ' + msg);
} catch (err) {
alert('Oops, unable to copy');
}
});
但它不起作用。如何以这种方式插入随机数?感谢。
答案 0 :(得分:1)