我想做的是将onchange事件绑定到未附加的元素。但这是我尝试过的:
class WrapperCell(tf.nn.rnn_cell.RNNCell):
"""A Wrapper for a non recurrent component that feeds into an RNN."""
def __init__(self, model_fn, out_shape, reuse=None):
super(WrapperCell, self).__init__(_reuse=reuse)
self.out_shape = out_shape
self.model_fn = model_fn
@property
def state_size(self):
return tf.TensorShape([1])
@property
def output_size(self):
return tf.TensorShape(self.out_shape)
def call(self, x, h):
mod = self.model_fn(x)
return mod, tf.zeros_like(h)
但是这不起作用,我如何将on change事件绑定到尚未附加的元素?
答案 0 :(得分:3)
您需要将jQuery对象直接存储在变量中,并将事件处理程序附加到该变量,而不是HTML:
var $container = $('.test');
let input = $(`<input class="form-control" type="number" name="test" step="any" min="0">`);
input.on('change', function(e){
console.log('test');
});
$container.html('');
$container.append(input);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test"></div>