gpt4 book ai didi

javascript - jQuery:Javascript 在设置值时抛出错误 "The operation is insecure"

转载 作者:可可西里 更新时间:2023-11-01 01:57:57 27 4
gpt4 key购买 nike

我正在尝试为不解释输入元素的占位符属性的浏览器寻找后备解决方案。我有这个简单的 jQuery 脚本,但它会抛出一个错误

SecurityError: "The operation is insecure.
this.value = val;"

这是我的脚本:

$('document').ready(function(){
$('input').each(function() {
if ($(this).val() === '' || $(this).val() === undefined) {
$(this).val($(this).attr('placeholder'));
}
});
});

有人知道我能做什么吗?或者我做错了什么?或者这个错误是什么意思?它发生在 Firefox 中,尚未在其他浏览器中测试过。

最佳答案

我刚刚在我的项目中修复了一个类似的问题。事实证明,我试图设置一个 <input type="file" ...> 的值。输入。看来您可能面临同样的问题,因为您正在选择文档的所有输入,而不管它们的类型。

如果您安装了 Firebug ,请尝试通过插入 log 来查找导致此错误的输入在尝试修改输入的值之前执行命令。

$('document').ready(function(){
$('input').each(function() {
if ($(this).val() === '' || $(this).val() === undefined) {

// Log goes here
window.console.log(
'There is an input without a value!',
this);

$(this).val($(this).attr('placeholder'));
}
});
});

关于javascript - jQuery:Javascript 在设置值时抛出错误 "The operation is insecure",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11780959/

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