I am trying to find a fallback solution for browsers who do not interpret the placeholder attribute for input elements. I have this simple jQuery Script but it throws an Error
我试图为那些不解释输入元素的占位符属性的浏览器找到一个后备解决方案。我有这个简单的jQuery脚本,但它会抛出一个错误
SecurityError: "The operation is insecure.
this.value = val;"
Here's my script:
这是我的脚本:
$('document').ready(function(){
$('input').each(function() {
if ($(this).val() === '' || $(this).val() === undefined) {
$(this).val($(this).attr('placeholder'));
}
});
});
Anyone any ideas what i can do? Or what i am doing wrong? Or what this error means? It happens in Firefox, haven't tested it in other Browsers yet.
任何想法我能做什么?或者我做错了什么?或者这个错误意味着什么?它发生在Firefox中,还没有在其他浏览器中测试过。
27
I have just fixed a similar problem in my project. It turned out that I was trying to set a value of a <input type="file" ...>
input. It seems that you may be facing the same problem, because you are selecting all inputs of a document regardless of their type.
我刚刚在我的项目中解决了类似的问题。事实证明,我试图设置输入的值。您似乎可能面临同样的问题,因为您正在选择文档的所有输入,而不管其类型如何。
If you have firebug installed, try looking for the input that causes this error by inserting a log
command before trying to modify the input's value.
如果安装了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'));
}
});
});
0
I had an insecure warning in conjunction with antoher function. The reason there simply was, that a library function was called with an array given as parameter, but it expected an element (dom). The result was the expected, but I'm sure, this won't be in any case. So check if the types of your variables are the one you (or the other side) want's it to.
我有一个不安全的警告和antoher功能。原因就在于,使用作为参数给出的数组调用库函数,但它期望一个元素(dom)。结果是预期的,但我敢肯定,这不会是任何情况。因此,请检查变量的类型是否是您(或另一方)想要的变量类型。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/08/02/87d28aed5a4af863354c15db979139e0.html。