create_row()函数存在问题
Problems with create_row() function
全部,
此javascript代码根据用户对下拉框的选择动态添加输入框。我几乎把它放在了需要的地方,但现在,当我测试时,"msds_copy"answers"cofa_copy"情况都显示了"html2"的相同数据。选择"msds_copy"应使第二个表单框显示"Region/Language",而不是显示"Batch Number"。
你知道为什么会发生这种事吗?
inquiry_type_onchange: function(e) {
var place_order = 1,
order_status = 2,
telalert_signup = 3,
invoice_questions = 4,
msds_copy = 5,
cofa_copy = 6,
html = null,
html2 = null,
inquiry = e.target,
id = "inquiry_type_addendum",
form_row = dojo.query("."+id);
//Clear any possible previous additions.
if (form_row != null)
form_row.forEach(dojo.destroy);
//Add the correct new field to the form.
switch (inquiry.selectedIndex) {
case place_order:
html = this.create_form_row(id, "Account Number:");
break;
case order_status:
html = this.create_form_row(id, "Order Number:");
break;
case telalert_signup:
html = this.create_form_row(id, "Account Number:");
break;
case invoice_questions:
html = this.create_form_row(id, "Invoice Number");
break;
case msds_copy:
html = this.create_form_row(id, "Product Name:");
html2 = this.create_form_row(id + "_2", "Region / Language:");
case cofa_copy:
html = this.create_form_row(id, "Product Name:");
html2 = this.create_form_row(id + "_2", "Batch Number:");
default:
}
if (html == null) return;
//Place the new element below the inquiry_type field.
var placeat = dojo.byId('buttons');
dojo.place(html, placeat, "before");
if(html2!=null)
dojo.place(html2, placeat, "before");
},
create_form_row: function(id, label) {
//Container
var a = dojo.create("div", { id: id, className: "question inquiry_type_addendum", style: "padding-top:4px;" });
//Label
var b = dojo.create("div", { className: "label", innerHTML: label, style: "margin-top:8px;" }, a);
//Field
var c = dojo.create("div", { className: "field" });
var d = dojo.create("span", { className: "full_number_span span" });
var e = dojo.create("input", { type: "text", className: "textbox full_number", name: label }, d);
dojo.place(d, c);
dojo.place(c, a);
return a;
}
});
您丢失了break
,开关情况msds_copy
正在执行,然后切换到下一个情况cofa_copy
。
case msds_copy:
html = this.create_form_row(id, "Product Name:");
html2 = this.create_form_row(id + "_2", "Region / Language:");
break; // <----
case cofa_copy:
html = this.create_form_row(id, "Product Name:");
html2 = this.create_form_row(id + "_2", "Batch Number:");
break; // <----
相关文章:
- IE9的HTML5 Canvas getImageData()函数存在问题
- 如何添加函数中存在的所有参数
- 如何将一个函数附加到一个不存在的元素上
- 当提供函数名称时,检查函数是否存在于同一作用域中
- 运行时不存在Javascript函数
- 如何使用函数来确定 Javascript 数组中是否存在值
- 在运行Javascript/jQuery中的函数之前,检查元素是否存在是否更具性能
- TypeError:$(..).higharts不是函数-现有解决方案不起作用-Yeoman生成器存在问题
- 检查D3.js中的函数中是否存在URL
- 在Require.js中,如果Require()是一个函数,那么Require.config()是如何存在的
- javascript className函数存在问题
- this.function不是函数错误,但函数存在
- jquery中的click函数存在问题
- 与变量值同名的函数存在,但是接收到typeError,为什么?
- create_row()函数存在问题
- JavaScript:重构对象中的方法和函数存在问题
- 为什么getUTCSeconds和getUTCMilliseconds函数存在?
- 匿名函数和命名函数存在疑问
- 未捕获的类型错误:不是函数,但函数存在
- 当有一个警报函数存在时,回调会被触发,如果没有警报,它不会被触发