0

在这里我想做的是基于if条件的值,应该禁用总表单,我该怎么做,这是我尝试过的代码....

if ($today1 >= $saturday && $today1 <= $season1)
    {
     document.getElementById('season').disabled = false;
    }
    else if($today1 >= $startdate_offseasona1 && $today1 <= $enddate_offseasona1 )
    {
    document.getElementById('season').disabled = true;
    }
    else if($today1 >= $startdate_seasona2 && $today1 <= $season2)
    {
    document.getElementById(seasons).disabled = false;
    } 

我的表格如下:

<form action="" method="POST" id="season" name="season">
Min_Custom_League_size<input type="text" name="min_custom_league_size" size="40"/><br/>
Max_Custom_League_size:<input type="text" name="max_custom_league_size" size="40"/><br/>
Ranked_League_size:<input type="text" name="ranked_league_size" size="40"/><br/>
Screen_Capacity:<input type="text" name="screen_capacity" size="40"/><br/>
Wide_Release_Screens:<input type="text" name="wide_release_screens" size="40"/><br/>
Limited_Release_Screens:<input type="text" name="limited_release_screens" size="40"/><br/>
Starting_Auction_Budget:<input type="text" name="starting_auction_budget" size="40"/><br/>
Weekly_Auction_Allowance:<input type="text" name="weekly_auction_allowance" size="40"/><br/>
Minimum_Auction_Bid:<input type="text" name="minimum_auction_bid" size="40"/><br/>
<input type="submit" value="submit" name="submit" />
</form>

我如何根据 if 条件值执行此操作...我的代码有什么问题?

4

2 回答 2

1

您正在混合 PHP(服务器端)和 JavaScript(客户端),但您不能这样做。无论如何,您必须禁用<input>元素,而不是表单本身。

以下是仅使用 PHP 的方法:

<?php
$disableForm = $today1 >= $startdate_offseasona1 && $today1 <= $enddate_offseasona1;
?>
<form action="" method="POST" id="season" name="season">
    Min_Custom_League_size<input type="text" <?php if($disableForm) echo 'disabled="disabled"'?> name="min_custom_league_size" size="40"/><br/>
<!-- repeat for all input elements -->
</form>

这是一种无条件禁用输入的纯 JavaScript 方法:

<script>
window.onload = function() {
    var frm = document.getElementById('season');
    var inputs = frm.getElementsByTagName('input');
    for(var i=0; i<inputs.length; i++) {
        inputs[i].disabled = true;
    }
}
</script>

注意:您的最后一个else if块中也有一个错字,应该是disabled,而不是diabled

于 2012-05-19T14:50:47.803 回答
0

使用它来禁用表单中的所有元素。同样,您可以启用表单元素

var theform = document.getElementById('seasons');
for (i = 0; i < theform.length; i++) {
var formElement = theform.elements[i];
if (true) {
formElement.disabled = true;
}
}
于 2012-05-19T14:59:35.000 回答