Php 连接两个简单的jquery条件
我制作了一个php表单,如果满足某些条件,我想在其中显示一个加载gif。下面是一个可读的psuedo代码/我需要在jquery中使用的逻辑示例Php 连接两个简单的jquery条件,php,jquery,forms,Php,Jquery,Forms,我制作了一个php表单,如果满足某些条件,我想在其中显示一个加载gif。下面是一个可读的psuedo代码/我需要在jquery中使用的逻辑示例 if (file_input_is_set && submit_button_is_clicked) { <div class="progress-bar">tada...loading_gif</div> } jQuery().on('change', 'input[type="file"]', f
if (file_input_is_set && submit_button_is_clicked) {
<div class="progress-bar">tada...loading_gif</div>
}
jQuery().on('change', 'input[type="file"]', function(e) {
jQuery("input[name='profile_submit']").click(function (e) {
//jQuery('#submit-button').hide();
jQuery('.progress-bar').fadeIn(1000);
});
});
第二个代码显示单击表单提交按钮时加载的gif
jQuery("input[name='profile_submit']").click(function (e) {
因为我对jQuery几乎一无所知,所以我需要帮助将这些事件组合在一起。如果我的术语有误,请原谅。这里是我尝试过的不起作用的,它显示了加载gif,甚至在我按下提交按钮之前。所以我需要一个像php的&&
操作符一样工作的函数,我不知道在jquery中如何做到这一点
if (file_input_is_set && submit_button_is_clicked) {
<div class="progress-bar">tada...loading_gif</div>
}
jQuery().on('change', 'input[type="file"]', function(e) {
jQuery("input[name='profile_submit']").click(function (e) {
//jQuery('#submit-button').hide();
jQuery('.progress-bar').fadeIn(1000);
});
});
注意:您在代码中看到大量jQuery
的原因是由于wordpress(使用表单)需要处于无冲突模式
重新表述的问题(来自@webkit的提示):我如何同时检查 触发提交事件时,文件输入是否已设置/有效
从最后一个操作开始,表单提交。然后检查文件输入中是否存在文件:
jQuery("input[name='profile_submit']").click(function (e) {
if( jQuery('input[type="file"]').val() != '' ){
jQuery('.progress-bar').fadeIn(1000);
}
});
jsiddle演示:您可以这样做:
jQuery("input[name='profile_submit']").click(function (e) {
// check to see if file is valid
if (jQuery('input[type="file"]').val() != "") {
// load
jQuery('.progress-bar').fadeIn(1000);
}
});
或者:(只有选择文件后,您才会激活提交btn)
检查条件和检查事件(更改,单击..)之间有区别。您可以将事件委托给一个处理程序,或者在提交事件触发器时,也可以检查输入是否有效,是。我必须刷新缓存才能看到更改。对不起,我之前没意识到。