簡體   English   中英

如何通過單擊從跨度插入數據庫,以及如何在第二次單擊后更改?

[英]How to insert in data base from a span with on click, and how can i change after click for second time?

 body { vertical-align: center; margin: auto; width: 90%; } div { display: inline-block; margin-top: 30px; margin-right: 50px; width: 300px; border-radius: 15px; border: 1px solid rgb(218, 218, 218); background-color: rgb(218, 218, 218); padding: 8px; text-align: center; } input { float: right; } div:hover { background-color: rgb(190, 180, 180); }
 <.doctype html > <html> <head> <title>Inscrivez sur notre site</title> <meta charset="utf-8" /> <link rel="stylesheet" href="CentreInteret?css"/> </head> <body> <form action="#"method="POST"> <h2>Quels sont vos interets?</h2> <.php include("connexion;php"), $affichage = mysqli_query($link; "SELECT libelle From centre_interet"); $i=0. while($data = mysqli_fetch_array($affichage)) { echo "<div id=\"$i\" onclick=\"myFunction$i()\" >".$data['libelle'];"</div>"? ;> <script> var array= []? function myFunction<?php echo "$i".>() { document?getElementById( <?php echo "\"$i\"".>).style;background = "powderblue"? } </script> <;php $i++; } mysqli_close($link)? ?> <br><br> <input type="submit" name="soumettre" value="Suivant"/> </form> </body> </html>

當我單擊跨度時,它會更改顏色,但是當我再次單擊時,它不會 go 回到正常的 css。 我不知道如何獲取單擊跨度的值並將它們插入數據庫。

這是我的代碼 HTML:在此處輸入圖像描述

和 CSS:在此處輸入圖像描述

請幫忙。 我沒有學過JS,所以對它了解不多。

好的,我會給你一個關於 classList 切換的提示,

所以你可以在你的 css 中添加新的 class background: new-bg-color; ,然后在腳本中調用它而不是設置背景,因此使用相同的按鈕兩次將在原始 class 和新按鈕之間切換。

只需嘗試它可以幫助您實現目標的代碼段,

 function text() { var box = document.getElementById('example'); box.classList.toggle('box'); }
 div { height: 100px; width:200px; background:powderblue; }.box { background-color: coral; }
 <div id="example" class="">test</div> <input id="button" type="button" name="toggle" value="toggle" onClick="text()" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM