简体   繁体   English

如何将src的值输入输入然后在另一页上显示它?

[英]How to put the value of src to an input then display it on the other page?

I want to put the value of i.src into the input and then display the generated image on the other page using the post command 我想将i.src的值放入输入中,然后使用post命令在另一页上显示生成的图像

$('#create').bind('click', function(e) {
    var datapair = $sigdiv.jSignature("getData", "image");
    var i = new Image();
    i.src = "data:" + datapair[0] + "," + datapair[1];
    $('#displayarea2').empty();
    $(i).appendTo($("#displayarea2")); // append the image (SVG) to DOM.
    document.getElemenById('sig').value = i.src;  //store the value of i.src to input
    alert("done1");
});

then store the value here 然后在这里存储值

 <input type="image" id="sig" name="sig" />

then display it on the other page using this 然后使用此将其显示在另一页上

 <?php echo $_POST["sig"]; ?>

Am I doing this right? 我这样做对吗?

this is the sample 这是样品

sample telexperience.net76.net/sample.html 示例telexperience.net76.net/sample.html

the generated image must be stored in an input then be displayed on the other page using the $_POST 生成的图像必须存储在输入中,然后使用$ _POST显示在另一页上

Not sure I understand exactly what you're trying to do but you can assign whatever value you want to the input sig. 不确定我确切了解您要执行的操作,但是您可以将想要的任何值分配给输入信号。

$("#sig").val(youvaluegoeshere);

Then when the form is submitted you can access that value and display. 然后,在提交表单后,您可以访问该值并显示。 I am not sure I understand the rest of your code though. 我不确定我是否理解其余的代码。

jQuery(function(){
    jQuery('#create').bind('click', function(e) {
        var datapair = $sigdiv.jSignature("getData", "image");
        var img = jQuery("<img src='"+"data:" + datapair[0] + "," + datapair[1];+"' />");
        jQuery("input#sig").val(jQuery(img).attr("src"));
    })
});

You should just change from: 您应该从以下位置进行更改:

 <input type="image" id="sig" name="sig" />

to

 <input type="hidden" id="sig" name="sig" />

Notice that I changed the type from image to hidden . 注意,我将类型从image更改为hidden Some browsers do not send the value of image type input controls. 某些浏览器不发送图像类型输入控件的值。

Keep everything else as is and it should work fine. 将其他所有内容保持原样,它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM