简体   繁体   中英

How to get value from span and put it into variable using php

OK , This is my Html code :

<span id="d"></span>

And this is my Java Script code :

<script>document.getElementById('d').innerHTML = (date.format('DD'));</script>

Now span have a value , I want to get this value from Span and put it into variable then insert it into Database but i don't know how to get value from span .

but i don't know how to get value from span .

Just use the same property, you used to set the so called "value" to get it as well.

var value = document.getElementById('d').innerHTML;

After doing the above you'll be able to send it to your backend with ajax.

This way you will get value

var value = document.getElementById('d').innerHTML;

Use Jquery Ajax to post the value from id then save it in database

$.ajax({
   url : pathofyoursavingphpscript.php
   data : {divVal:value} 
   success:function(data){
      alert('value is saved in database');
   }
})

您可以使用它来获取值并将其添加到 php 变量中

$v = "<script> document.write(document.getElementById('d').innerHTML) </script>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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