javascript - 使用javascript在声明的变量中创建按钮

标签 javascript html

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/

相关文章:

javascript - 如何在用户单击第二个下拉菜单时关闭第一个下拉菜单?

javascript - 当我上传代码时,我的代码无法在 CodePen 或 JsFiddle 上运行,但在浏览器中运行良好。有人可以帮助我吗?

javascript - 将 javascript 从 onclick 转换为 onhover

javascript - 在 Angular 中将环境变量设置为常量

javascript - 手动更改 aria-expanded ="true"不打开新选项卡

javascript - iframe 仅在 IE8/9 中显示垂直滚动条

php - 如何让随机图像每次刷新一个样式表,但在选择另一个样式表时消失?

php - 使用 php 从数据库中获取 HTML 文本

javascript - jquery FullCalendar - 项目被复制

javascript - 如何在 php laravel 的第二页保留过滤器选项?