JQuery.val () not working in Facebox

I use Facebox ( http://defunkt.github.com/facebox/ ) on one of my sites. I also make extensive use of jQuery on the site.

My problem is that the .val () function does not work inside facebox. Now this is a DIV that displays as facebox:

<div id="edit-tags" style="display: none;">
  <script type="text/javascript">   
   $('.add-tag-form').submit(function(){
    alert($('input.tags-input').val());
    return false;
   });
  </script>

  <form class="add-tag-form">
   <input type="text" name="tags-input" class="tags-input" />
   <input type="submit" class="small-button" value="Add Tag" />
  <form>
</div>

Now the problem is that the value input.tags-inputdoes not appear in the warning window. It appears blank.

To make the problem worse, jQuery selection really works. That is, it $('input.tags-input').hide()works fine.

To make the problem worse, it .val()works with the initial value. That is, if I use this:

<input type="text" name="tags-input" class="tags-input" value="Some value" />

Then in the warning window “Some value” is displayed, regardless of whether I change the value or not.

. .val() facebox.

+3
6

,

$(function() { ... });
       or
$(document).ready(function() { ... });

$(function() {
   $('.add-tag-form').submit(function(){
      alert($('input.tags-input').val());
      return false;
   });
});

, ,

+2

facebox.js 254 change
$. facebox.reveal($ (target).clone(). show(), klass) to
$. facebox.reveal($ (target).show(), )

Facebox div, . .val(), div, div ( ) div.

. , , - (facebox div , , )

+2

, div, .

() , :

$('#input_field_id').live('keyup', function() {
  $('#input_field_id').val($(this).val());
});

, .

: ! #facebox , . :

$('#facebox #input_field_id').val();

,

    $(document).bind('reveal.facebox', function() { 
+2

, javascript- . $('. Add-tag-form'), jquery , , .

, , , jQuery, , . :

$(document).ready(function(){
    ...
});

, , jquery, :

(function ($){
   $(document).ready(function() {
       ...
   });
})(jQuery);

, - $, script , $shortcut.

+1

I am stuck from the last day on it. In my case, facebox.js showed up at no 243-> $ .facebox.reveal ($ (target) .html (), class), and I change it to $ .facebox.reveal ($ (target) .show () , class) and it works. Thanks for all of the above posts.

+1
source

Finally, I want to update this post that I used a lightbox instead of facebox to get rid of the problem of submitting a form to facebox, and it worked in the first attempt. A backlit label has another option and gives a better result than facbox

0
source

Source: https://habr.com/ru/post/1766035/


All Articles