我有这个功能,它创建一个具有特定值的按钮。在我的html表单中,我有一个复选框。我希望按钮中的值添加到复选框中。由于某种原因,我无法弄清楚..
功能:
var showDate = new Date();
var months = ["Januari", "Februari", "March", "April", "May", "June","July", "Augusti", "September", "October", "November", "December"];
var weeks = ["Sunday","Monday","Tuseday","Wednesday","Thursday","Friday","Saturday"];
var theForm = '<form class="" method="post">
<input id="day"type="checkbox" name="day" value=""> //the checkbox where I want the value to be in
<input id="button" type="submit" name="btn" 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 );
newRow.appendChild(textarea);
textarea.setAttribute("name", "day");
textarea.setAttribute("value", newdate + "-" + day1); //the value that I want to add in the checkbox
textarea.innerHTML = day1;
var textarea1 = document.createElement("div");
newRow.appendChild(textarea1);
textarea1.innerHTML = theForm;
cellsToDraw--;
}
}
}
所有帮助都是适当的! :) (我删除了一些不必要的代码!)
答案 0 :(得分:0)
it('each object in allFeeds array should have a URL value associated with each key', function() {
allFeeds.forEach(function (arrayItem) {
var x = arrayItem.url
return x;
});
expect(x).not.toBeUndefined();
});
在按钮上添加事件侦听器,然后将按钮的值分配给复选框的值。
看起来有点像你渲染一个复选框和按钮列表,在这种情况下你需要编写一个循环,为每个按钮添加一个事件监听器,它是相应的复选框