我已经在下降 div 中造词,我的代码示例在这里:
http://jsfiddle.net/apHLu/674/embedded/result/
但我不明白为什么我不能在 div 的可点击中造词。有时我可以单击它并看到带有单词的警报消息,但有时我应该单击上面的单词才能看到警报消息。也许是因为这种动画方式很慢?
我的代码的主要部分:
/* Start by creating a wrapper div, and an empty img element */
var leafDiv = document.createElement('div');
var image = document.createElement('div');
/* Randomly choose a leaf image and assign it to the newly created element */
image.innerHTML = phrase[counter];
image.style.padding = "40px 0 0 20px";
leafDiv.style.backgroundColor = "#eee";
leafDiv.setAttribute('data-url', counter);
leafDiv.setAttribute('data-text', phrase[counter]);
leafDiv.onclick = function () {
alert($(this).attr('data-text'));
};
leafDiv.style.top = "-100px";