jquery attr 在 Chrome 中不起作用?
var select_tag = $('<select></select>').attr( {
onchange: 'createDiscipline()',
class: 'select_menu'}
).fadeIn('slow');
这在 FF 中有效,但在 Chrome 中无效。 Chrome 中发生的情况是,类已设置,但 createDisicipline() 未设置。
这是向标签添加多个属性的错误方法吗?它确实适用于 FF :/
整个代码:
var select_tag = $('<select>', {
onchange: createDiscipline,
'class': 'select_menu'}
).fadeIn('slow');
for(i = 0; i < c_data.length; i++) {
select_tag.append('<option>' + c_data[i] + '</option>');
}
//wrap select_tag in div
var div_buffer = $('<div class=\'select_buffer\'></div>');
var div_container = $('<div class=\'select\'></div>');
div_buffer.append(select_tag).wrap('<div class=\'select_buffer\' />');
div_container.append(heading);
div_container.append(div_buffer);
//Append to the page after right_content id
$('#right_content').append(div_container)
var select_tag = $('<select></select>').attr( {
onchange: 'createDiscipline()',
class: 'select_menu'}
).fadeIn('slow');
This works in FF but not Chrome. What happens in Chrome is that the class is set, but the createDisicipline() isn't.
Is this the wrong way to add multiple attrs to a tag? It does work in FF :/
ENTIRE CODE:
var select_tag = $('<select>', {
onchange: createDiscipline,
'class': 'select_menu'}
).fadeIn('slow');
for(i = 0; i < c_data.length; i++) {
select_tag.append('<option>' + c_data[i] + '</option>');
}
//wrap select_tag in div
var div_buffer = $('<div class=\'select_buffer\'></div>');
var div_container = $('<div class=\'select\'></div>');
div_buffer.append(select_tag).wrap('<div class=\'select_buffer\' />');
div_container.append(heading);
div_container.append(div_buffer);
//Append to the page after right_content id
$('#right_content').append(div_container)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您绝对不应该尝试像这样绑定事件处理程序。以不引人注目的方式进行:
注意我的变化。我将
class
括在引号中,因为它是 InternetExplorer 中的关键字,否则可能会破坏您的代码。我还将新创建的演示:http://jsfiddle.net/vM5Hp/
You should definitely not try to bind an event handler like this. Do it the unobtrusive way:
Notice my changes. I wrapped
class
in quotes because it is a keyword in InternetExplorer and may break your code otherwise. Also I appended the newly created<select>
node to the document.body.Demo: http://jsfiddle.net/vM5Hp/