i有一组褪色的图像,并在选择图像时褪色并褪色。这是工作。 Whenever an image is selected some information about that picture is shown beside list of images.它也在工作。但目前我需要在该文本中有一个按钮,每张图片都不同。谁能指导我如何做到这一点? 对于文本,在脚本中有一个包含文本数组的变量,比如-
var line = [{
"caption": "Violet",
"content": "It is 1st color of VIBGYOR.",
}, {
"caption": "Blue",
"content": "It is third color of VIBGYOR."
}, {
"caption": "Orange",
"content": "It is sixth color of VIBGYOR."
}]
函数是:
function motionStart(e, data) {
$(".title, .text", this).hide().removeClass('animated fadeInDown fadeInUp');
}
function motionEnd(e, data) {
var text = line[data.index % line.length];
$(".title, .text", this).show();
$(".title", this).text(text.caption).addClass('animated fadeInDown');
$(".text", this).text(text.content).addClass('animated fadeInUp');
}
function carouselCreated(e, data) {
motionEnd.call(this, e, data)
}
我要插入 document.write('<button type="button">Click Me!</button>')
对于每个。单击按钮后,它将显示另一个页面。
如果可能请帮忙。
最佳答案
我看到您正在使用 JQuery。
您可以使用:
var button = $('<button type="button">' + someJsVar + '</button>');
然后将其附加到 dom:
$('body').append(button);
关于javascript - 使用javascript在声明的变量中创建按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36712540/