我的应用程序有一个区域需要用户同意一个声明,并且我正在使用 Javascript/jQuery,因此当用户选择“是”时,它会自动将日期/时间输入到只读字段中。
虽然我无法重现它,但我有多个用户告诉我,当他们选择“是”时,它不会填充日期/时间,并且由于该字段是只读的,他们无法自己输入。
我的代码中是否有任何非常规的内容会在特定浏览器中导致上述问题?任何人都可以在他们的机器上重现这个吗?
这是一个工作示例:http: //jsfiddle.net/YL2Wd/
HTML:
<div>
<label>I agree:*</label>
<span class="options">
<label for="agreement_no">No</label>
<input type="radio" class="required authorization" value="0" id="agreement_no" name="agreement">
<label for="agreement_yes">Yes</label>
<input type="radio" class="required authorization" value="1" id="agreement_yes" name="agreement">
</span>
</div>
<div class="description">
Agreement Text
</div>
<div class="question">
<label for="authorization_timestamp">Date/Time*</label>
<input type="text" readonly="readonly" maxlength="100" class="authorization_timestamp required" name="authorization_timestamp" id="authorization_timestamp">
</div>
Javascript:
$('.authorization[id$="yes"]').on('change', function() {
var dateStr;
if ($(this).val() == 1) {
var now = new Date();
var month = now.getMonth() + 1;
var day = now.getDate();
var year = now.getFullYear();
var h = now.getHours();
var m = now.getMinutes();
var s = now.getSeconds();
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
dateStr = month + "/" + day + "/" + year + " " + h + ":" + m + ":" + s
}
$(this).parent().parent().nextAll().find(".authorization_timestamp").first().val(dateStr);
});
$('.authorization[id$="no"]').on('change', function() {
var dateStr;
dateStr = "";
$(this).parent().parent().nextAll().find(".authorization_timestamp").first().val(dateStr);
});