首页 > 解决方案 > 如何在 JavaScript 中动态生成表单?

问题描述

我在 javascript 中动态创建了图像(记录器缩略图)。我想将此图像的图像路径发送到另一个文件。

我想我无法获得图像 ID。我根本无法转到另一个文件。图像已关闭。

window.onload = function() {
    var message = {id : 'vodList'}
    sendMessage(message);


    document.getElementById(bb).addEventListener('click', function() { vodPlayer(); });
}

ws.onmessage = function(message) {
    for (var i=0; i<parsedMessage2.length; i++){
    createImage = document.createElement("img");
    createImage.setAttribute('src', parsedMessage2[i].vod_thumbnail);
    createImage.setAttribute('alt', '100%x280');
    createImage.setAttribute('height', '280px');
    createImage.setAttribute('width', '100%');
    createImage.setAttribute('id', 'vodThumbnailId');
    document.getElementById('vodListId').appendChild(createImage);

    vodPath = JSON.stringify(parsedMessage2[i].vod_path);
  }
}

function vodPlayer() {
    var form = document.createElement('form');
   form.setAttribute('charset', 'UTF-8');
   form.setAttribute('method', 'Post');
   form.setAttribute('action', 'vodPlayer.html');

    var hiddenField = document.createElement('input');
                     hiddenField.setAttribute('type', 'hidden');
                     hiddenField.setAttribute('name', 'vodPath');
                     hiddenField.setAttribute('value', vodPath);
                     form.appendChild(hiddenField);

document.body.appendChild(form);
                     form.submit();

}

我希望你能帮助我。

标签: javascripthtmlformsjsp

解决方案


推荐阅读