jQuery: Javascript throws Error “The operation is insecure” when setting value

后端 未结 2 523
迷失自我
迷失自我 2020-12-06 10:48

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 Err

相关标签:
2条回答
  • 2020-12-06 11:25

    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.

    $('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 讨论(0)
  • 2020-12-06 11:37

    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.

    0 讨论(0)
提交回复
热议问题