如何处理< div>作为表格< input> [英] How do I process a <div> as a form <input>

查看:70
本文介绍了如何处理< div>作为表格< input>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的是:

HTML

<form>
    <div id="textBox" contenteditable="true" name="textBox"><?php echo $storyText; ?>
    </div>
    <textarea id="hiddeninput" name="hiddeninput"></textarea>
    <input type="submit" id="save" name="save" value="Submit"/>
</form>

Javascript

Javascript

$('#save').click(function () {
    var mysave = $('#textBox').html();
    $('#hiddeninput').val(mysave);
    $("form:first").submit();
    $('#hiddeninput').append(mysave);
    alert($('#hiddeninput').val());
});

因此,警报和附加信息都会显示正确的信息,但不会将#hiddeninput保存为我提交时的php变量。最初我把它作为一种隐藏输入法,但我试图证明无论我做什么它都不会发布,

So both the alert and the append display the correct information, but it won't save #hiddeninput as a php variable when I submit. Originally I had this as an hidden input method, but I'm trying to show that it won't post no matter what I do,

推荐答案

您的代码几乎可以正常运行。
但是我宁愿使用普通的< input type =hidden> 而且你不需要触发 submit 对于您的表单,只需将值放在隐藏字段中。

Your code is working almost as it is. But I'd rather use normal <input type="hidden"> and you don't need to trigger submit for your form in your case just put the value in a hidden field.

给定您的标记,稍作修改

Given your markup, with slight modifications

<form action="showrequest.php">
<div id="textBox" contenteditable="true" name="textBox" style="width:300px;height:100px;">
</div>
<textarea id="hiddeninput" name="hiddeninput"></textarea>
<input type="submit" id="save" name="save" value="Submit"/>
</form>

js

$(function(){
    $('#save').click(function () {
        var mysave = $('#textBox').html();
        $('#hiddeninput').val(mysave);
    });
});

php侧面的var_dump($ _ REQUEST)给出

array(2) {
  ["hiddeninput"]=>
  string(4) "test"
  ["save"]=>
  string(6) "Submit"
}

这篇关于如何处理&lt; div&gt;作为表格&lt; input&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆