gpt4 book ai didi

jquery - IE 忽略 jQuery .val()

转载 作者:行者123 更新时间:2023-12-01 03:01:37 25 4
gpt4 key购买 nike

我有以下 jQuery 代码,用于在搜索表单的末尾添加“清除”按钮:-

$('#search-tools input:last').after($('<input>',{
'class': 'search-clear'
, 'val': 'Clear'
, 'type': 'submit'
, 'click': function() {
// do something
}
}));

这适用于除 IE 之外的所有浏览器;在 IE 中,输入按钮未设置值“清除”,而是显示“提交查询”。我是否错误地设置了 val 或者这是 jQuery 的已知 IE 问题?

最佳答案

我已经弄清楚了...
您必须在 'type' 属性之后定义 'value' 属性:

$('<input>', {
'class': 'search-clear',
'type': 'submit',
'value': 'Clear',
'click': function() {
// do something
}
})

现场演示: http://jsfiddle.net/b8mk6/10/

<小时/>

'type'属性设置为'submit'<时,IE 清除'value'属性的值。所以:

var input = document.createElement( 'input' );

input.value = 'test...';
input.type = 'submit'; // the value is cleared

document.body.appendChild( input );

现场演示: http://jsfiddle.net/Z3xQ5/1/

关于jquery - IE 忽略 jQuery .val(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8563981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com