我有一个表单,允许用户选择付费频率(例如每小时)并显示年化因子(2080,每小时)。我的代码允许用户修改年度化因子,但我希望它只显示,而不是可编辑。有人可以帮忙吗?
代码:
function register() {
document.all.NewFrequency.onchange = OnChange;
}
function Init() {
var selectionValue = document.all.AnnualizingFactor;
register();
if (selectionValue.value == "") {
OnChange();
}
}
function OnChange() {
var selectValue = document.all.NewFrequency;
var selectionValue = document.all.AnnualizingFactor;
if (selectValue.options[selectValue.selectedIndex].value == "Yearly" ) {
selectionValue.value = "1";
}
if (selectValue.options[selectValue.selectedIndex].value == "Weekly") {
selectionValue.value = "52";
}
if (selectValue.options[selectValue.selectedIndex].value == "Unit") {
selectionValue.value = "2080";
}
if (selectValue.options[selectValue.selectedIndex].value == "SemiWeekly") {
selectionValue.value = "104";
}
if (selectValue.options[selectValue.selectedIndex].value == "Semimonthly") {
selectionValue.value = "24";
}
if (selectValue.options[selectValue.selectedIndex].value == "Quarterly") {
selectionValue.value = "4";
}
if (selectValue.options[selectValue.selectedIndex].value == "Monthly") {
selectionValue.value = "12";
}
if (selectValue.options[selectValue.selectedIndex].value == "Hourly") {
selectionValue.value = "2080";
}
if (selectValue.options[selectValue.selectedIndex].value == "Daily") {
selectionValue.value = "365";
}
if (selectValue.options[selectValue.selectedIndex].value == "Biweekly") {
selectionValue.value = "26";
}
if (selectValue.options[selectValue.selectedIndex].value == "None") {
selectionValue.value = "0";
}
}
答案 0 :(得分:0)
正如@ j08691所说,你必须只读标记字段:
<input type="text" readonly name="AnnualizingFactor" />
或以编程方式设置输入的readonly属性:
function Init() {
var selectionValue = document.all.AnnualizingFactor;
selectionValue.readonly = true;
register();
if (selectionValue.value == "") {
OnChange();
}
}