从div获得价值。 [英] Get value from div.

查看:121
本文介绍了从div获得价值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从表单中的div元素中获取值而不是使用输入?



我知道这是一个愚蠢的问题,但我只是想知道它是否可能。有点像PHP DOM?



或者有什么方法可以在提交时将div更改为输入?

谢谢,

解决方案

内容转换为提交表单之前的(隐藏)输入。



它在jQuery中大致如下所示:

  $( '#myForm')。submit(function(){
$('#myHiddenInput')。val($('#myDiv')。html());
});

编辑:你们为什么在讨论AJAX?在这种情况下,不需要使用AJAX!


Is there a way to get the value from a div element within a form instead of using a input?

I know it's kinda a dumb question, but I just want to know if its possible. Something like PHP DOM?

Or is there a way to possible changing the div to an input when hitting submit?

Thanks,

解决方案

With Javascript, you can put the div's content into a (hidden) input right before you submit the form.

It will approximately look like this in jQuery:

$('#myForm').submit(function() {
  $('#myHiddenInput').val($('#myDiv').html());
});

Edit: Why are you guys talking about AJAX? There's no need of using AJAX in this situation!

这篇关于从div获得价值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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