我有这个功能,当用户按下按钮时,带有内容的手风琴会关闭。然后,用户可以将文本框中的值添加到mysql数据库中。但是,我希望按钮的值也可以添加到数据库中,但现在还没有。按钮(日)的值始终为空。
只要不隐藏日期输入,我的函数就是将日期输入值添加到数据库中。但我希望手风琴按钮中的值是用户填写表单时插入数据库中的值。
所有帮助都是适用的!
功能:
var showDate = new Date();
var theForm = `<form class="" action="insertIntoCalendar.php" method="post">
<input id="day"type="hidden" name="day" value=""><br>
<input id="formInputPwd" type="text" name="message" value="" placeholder="Message"><br>
<input id="formInputPwd" type="number" name="hours" value="" placeholder="Hours"><br>
<input id="btnCreateUser" type="submit" name="" value="Send">
</form>`;
function drawTable(forDate) {
var daysInMonth = new Date(forDate.getFullYear(),forDate.getMonth()+1,0).getDate();
var cellsToDraw = daysInMonth;
var newdate = forDate.getFullYear() +"-"+ ("0"+ (forDate.getMonth() + 1)).slice(-2);
var calendar = document.getElementById("calendar");
calendar.innerHTML = "";
for (var r = 0; r < (daysInMonth / 7); r++) {
var newRow = document.createElement("tr");
calendar.appendChild(newRow);
for (var c = 0; c < 31 && cellsToDraw > 0; c++) {
var day1 = ("0" + (c + 1)).slice(-2);
var textarea = document.createElement("button");
textarea.setAttribute("placeholder", day1 );
textarea.setAttribute("class", "row");
newRow.appendChild(textarea);
textarea.setAttribute("name", "day");
textarea.setAttribute("id", "day");
textarea.setAttribute("day", newdate + "-" + day1 );
textarea.setAttribute("value", newdate + "-" + day1);
textarea.innerHTML = day1;
var textarea1 = document.createElement("div");
textarea1.setAttribute("class", "content");
newRow.appendChild(textarea1);
textarea1.innerHTML = theForm;
cellsToDraw--;
}
}
var acc = document.getElementsByClassName("row");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
var content = this.nextElementSibling;
var active = checkIfAnyVisible();
if (active) {
active.className = 'content';
active.style.maxHeight = null;
}
if (content.style.maxHeight){
content.style.maxHeight = null;
content.className = 'content';
} else if (!checkIfAnyVisible()) {
content.style.maxHeight = content.scrollHeight + "px";
content.style.width = "100%";
content.className = 'content active';
}
});
}
答案 0 :(得分:0)
为什么你不采取另一个元素来发送动作参数?
<input type="hidden" name="actionName" value="send">
很容易,否则你必须让Ajax触发动作并发送你想要的参数。