我有一个带有一些输入元素的简单表单,如下所示:
<form action="..." method="post" id="myform">
<p>Early bird price</p>
<p>
<label for="earlymember">Members: 100 USD</label>
<input type="radio" id="earlymember" value="Early bird members, 100 USD">
<label for="earlynotmember">Not members: 120 USD</label>
<input type="radio" id="earlynotmember" value="Early bird not members, 120 USD">
</p>
<p>Normal price</p>
<p>
<label for="normalmember">Members: 200 USD</label>
<input type="radio" id="normalmember" value="Normal members, 100 USD">
<label for="normalnotmember">Not members: 120 USD</label>
<input type="radio" id="normalnotmember" value="Normal not members, 120 USD">
</p>
如何在日期前停用#normalmember
和#normalnotmember
无线电,例如{09}在jQuery
或简单的JavaScript?
(当然在此日期之后我需要更改这些无线电以启用和禁用其他无线电。)
答案 0 :(得分:3)
我高度建议您比较服务器端之前和之后之前的日期,因为最终用户可以轻松覆盖您的客户端 - 边码。但是,我仍然提供客户端解决方案,因为您没有提到您的服务器端环境。
Neither the property "name" nor one of the methods "getName()", "name()", "isName()", "hasName()", "__get()" exist and have public access in class "KhaliBundle\Entity\Product".
$(document).ready(function() {
var myDate = new Date("2015-09-30");
$('#normalmember,#normalnotmember').prop('disabled', $.now() < myDate.getTime());
});
答案 1 :(得分:1)
您可以获取当前日期,并将其与您定义的日期进行比较:
var date = new Date().getTime();
var compareDate = new Date("2015-09-30");
if (date < compareDate.getTime()) {
$('#normalmember, #normalnotmember').attr('disabled', true);
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="..." method="post" id="myform">
<p>Early bird price</p>
<p>
<label for="earlymember">Members: 100 USD</label>
<input type="radio" id="earlymember" value="Early bird members, 100 USD">
<label for="earlynotmember">Not members: 120 USD</label>
<input type="radio" id="earlynotmember" value="Early bird not members, 120 USD">
</p>
<p>Normal price</p>
<p>
<label for="normalmember">Members: 200 USD</label>
<input type="radio" id="normalmember" value="Normal members, 100 USD">
<label for="normalnotmember">Not members: 120 USD</label>
<input type="radio" id="normalnotmember" value="Normal not members, 120 USD">
</p>
&#13;