关于下面的回答,我的浏览器控制台中出现以下错误
根据浏览器控制台,此行上的错误
未捕获的TypeError:无法设置nullcal.php:26的属性“ onclick”(匿名函数)
当您单击日期而不是在一月,四月,十一月时,窗体不会打开。
像26上的代码来自控制台浏览器
document.getElementById('trigger0').onclick = function()
{showForm()};document.getElementById('trigger1').onclick = function()
{showForm()};document.getElementById('trigger2').onclick = function()
{showForm()};document.getElementById('trigger3').onclick = function()
{showForm()};document.getElementById('trigger4').onclick = function()
{showForm()};document.getElementById('trigger5').onclick = function()
{showForm()};document.getElementById('trigger6').onclick = function()
{showForm()};document.getElementById('trigger7').onclick = function()
{showForm()};document.getElementById('trigger8').onclick = function()
{showForm()};document.getElementById('trigger9').onclick = function()
{showForm()};document.getElementById('trigger10').onclick = function()
{showForm()};document.getElementById('trigger11').onclick = function()
{showForm()};document.getElementById('trigger12').onclick = function()
{showForm()};document.getElementById('trigger13').onclick = function()
{showForm()};document.getElementById('trigger14').onclick = function()
{showForm()};document.getElementById('trigger15').onclick = function()
{showForm()};document.getElementById('trigger16').onclick = function()
{showForm()};document.getElementById('trigger17').onclick = function()
{showForm()};document.getElementById('trigger18').onclick = function()
{showForm()};document.getElementById('trigger19').onclick = function()
{showForm()};document.getElementById('trigger20').onclick = function()
{showForm()};document.getElementById('trigger21').onclick = function()
{showForm()};document.getElementById('trigger22').onclick = function()
{showForm()};document.getElementById('trigger23').onclick = function()
{showForm()};document.getElementById('trigger24').onclick = function()
{showForm()};document.getElementById('trigger25').onclick = function()
{showForm()};document.getElementById('trigger26').onclick = function()
{showForm()};document.getElementById('trigger27').onclick = function()
{showForm()};document.getElementById('trigger28').onclick = function()
{showForm()};document.getElementById('trigger29').onclick = function()
{showForm()};document.getElementById('trigger30').onclick = function()
{showForm()};document.getElementById('trigger31').onclick = function()
{showForm()};document.getElementById('trigger32').onclick = function()
{showForm()};document.getElementById('trigger33').onclick = function()
{showForm()};document.getElementById('trigger34').onclick = function()
{showForm()}; function showForm(){
它涉及的代码是:
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = getdate();
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr> ";
if($i < $startday) echo "<td></td> ";
else echo "<td align='center' valign='middle' height='20px'><a href='#'
id='trigger" . $i . "'>". ($i - $startday + 1) . "</a></td>";
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick =
function() {showForm()};";
if(($i % 7) == 6 ) echo "</tr> ";
}
?>
javascript代码
<script type="text/javascript">
<?php foreach($jsEvent as $event){
echo $event;
} ?>
function showForm(){
document.getElementById('timeslots').style.display="block";
};
</script>
您可以使用javascript。您可以使用onClick =“”触发隐藏/显示表单的js函数。
<script type="text/javascript">
<?php foreach($jsEvent as $event){
echo $event;
} ?>
function showForm(){
document.getElementById('timeslots').style.display="block";
};
</script>
然后改变
<table width='400' border='2' cellpadding='2' cellspacing='2' id='timeslots'
style="visibility:invisible"'>
到
<table width='400' border='2' cellpadding='2' cellspacing='2' id='timeslots'
style="display:none;"'>
还要更改此:
<td align='center' valign='middle' height='20px'><a href='#'>". ($i - $startday + 1) . "</a></td>
对此:
<td align='center' valign='middle' height='20px'><a href='#' id='trigger" . $i . "'>". ($i - $startday + 1) . "</a></td>
请记住,“ editform”只是建议的ID,需要与您使用的触发器/日期的ID匹配。
我已经尝试并搜索了高低,但我无法提出另一个解决方案,用下面的代码替换您的for循环(for和其中的所有内容)
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ){
echo "<tr> ";
}
if($i < $startday){
echo "<td></td> ";
} else{
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick =
function() {showForm()};" . PHP_EOL;
echo "<td align='center' valign='middle' height='20px'><a href='#'
id='trigger" . $i . "'>". ($i - $startday + 1) . "</a></td>";
}
if(($i % 7) == 6 ){
echo "</tr> ";
}
}
JS函数可以更高级,例如检查或隐藏其他打开的表单,这只是一个简单的JS函数,它按ID显示单个表单
UPDATE根据来自注释:)的信息更新了我的答案,现在,您只需要更改第一个document.GetelemtentByID的ID即可匹配您要触发该功能的“链接/文本”的ID。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句