取消确认窗口但是

时间:2018-02-15 09:43:30

标签: javascript forms submit confirm

当我点击取消表格提交时(( 为什么? 我尝试添加到“”。一切都很好。但是,只有当tr backgorund颜色为黄色时我才需要确认。这样它就不会取消sumbmition ......

$('#cart_form').submit(function() {
    $("tr").each(function(indx, element)
    {

        if (element.style.backgroundColor=="rgb(255, 255, 179)"){
            var c = confirm("Are u sure?");
            return c;
        }
    });
});

1 个答案:

答案 0 :(得分:2)

return从您传递给each()的函数中submit()。请参阅the documentation,其中包含:

  

您可以通过返回false来阻止回调函数中的循环

循环,而不是表单提交!

您需要从传递给 # Create the Estimator classifier = tf.estimator.Estimator(model_fn=cnn_model) # Set up logging for predictions tensors_to_log = {"probabilities": "softmax_tensor"} logging_hook = tf.train.LoggingTensorHook(tensors=tensors_to_log, every_n_iter=10) # Train the model train_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": train_data},y=train_labels,batch_size=batch_size,num_epochs=None,shuffle=True) classifier.train(input_fn=train_input_fn, steps=200000, hooks=[logging_hook]) # Evaluate the model and print results eval_input_fn = tf.estimator.inputs.numpy_input_fn( x={"x": eval_data}, y=eval_labels, num_epochs=1, shuffle=False) eval_results = classifier.evaluate(input_fn=eval_input_fn) print(eval_results) #Sections of the cnn_model #Output Config predictions = { "classes": tf.argmax(input=logits, axis=1),# Generate predictions (for PREDICT and EVAL mode) "probabilities": tf.nn.softmax(logits, name="softmax_tensor")} # Add `softmax_tensor` to the graph. It is used for PREDICT and by the `logging_hook`. if mode == tf.estimator.ModeKeys.PREDICT: return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions) # Calculate Loss (for both TRAIN and EVAL modes) onehot_labels = tf.one_hot(indices=tf.cast(labels,tf.int32),depth=20) loss = tf.losses.softmax_cross_entropy(onehot_labels=onehot_labels, logits=logits) #Training Config if mode == tf.estimator.ModeKeys.TRAIN: optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate) tf.summary.scalar('training_loss',loss) summary_hook = tf.train.SummarySaverHook(save_steps=10,output_dir='outputs',summary_op=tf.summary.merge_all()) train_op = optimizer.minimize(loss=loss, global_step=tf.train.get_global_step()) return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op,training_hooks=[summary_hook]) # Evaluation Metric- Accuracy eval_metric_ops = {"accuracy": tf.metrics.accuracy(labels=labels, predictions=predictions["classes"])} print(time.time()-t) tf.summary.scalar('eval_loss',loss) ac=tf.metrics.accuracy(labels=labels,predictions=predictions["classes"]) tf.summary.scalar('eval_accuracy',ac) evaluation_hook= tf.train.SummarySaverHook(save_steps=10,output_dir='outputseval',summary_op=tf.summary.merge_all()) return tf.estimator.EstimatorSpec(mode=mode, loss=loss, eval_metric_ops=eval_metric_ops,evaluation_hooks=[evaluation_hook]) 的函数返回(或者更好地捕获给予该函数的第一个参数(the event object)和call preventDefault())。