简体   繁体   English

如何获取div值javascript php html

[英]How to get the div value javascript php html

Myhtml: MYHTML:

<form id="w" action="modify_review.php?act=transmitNext" method="POST">
<input id="title" name="title" value="" />
<div class="selected_staff" id="selected_staff" name="editor"></div>
</form>

modify_review.php: modify_review.php:

<?php
echo $_POST["title"];//works fine
echo $_POST["editor"];//failed
?>

How can i get the div value in myphp? 我如何在myphp中获得div值? who can help me ? 谁能帮我 ?

You have two ways to achieve this. 您有两种方法可以实现此目的。

  1. You can use textarea . 您可以使用textarea
  2. Use JavaScript to get the value with existing code structure (just one hidden input field need to be added). 使用JavaScript获取具有现有代码结构的值(只需添加一个隐藏的输入字段)。

    • Add hidden input by following attrs. 按照attrs添加隐藏的输入。 input type: hidden name: editor Id=selectedStuff 输入类型: hidden名称:编辑器Id=selectedStuff
    • bind getSelectedStuff method on onchange on div id=selected_stuff 在div id=selected_stuff onchange上绑定getSelectedStuff方法

       function getSelectedStuff(userInput){ // get user input var inputValue = userInput.value; //set value to hidden input document.getElementById("selectedStuff").value = inputValue; } 

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

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