“之后”;提交;JavaScript/jQuery
在Yii2中,当您单击“提交”并等待加载时,是否有可能出现一个窗口,或者至少显示一条消息“正在加载,请耐心等待”?我对JavaScript几乎没有经验,但我想这就是解决问题的方法。 我试过:“之后”;提交;JavaScript/jQuery,javascript,php,jquery,yii2,Javascript,Php,Jquery,Yii2,在Yii2中,当您单击“提交”并等待加载时,是否有可能出现一个窗口,或者至少显示一条消息“正在加载,请耐心等待”?我对JavaScript几乎没有经验,但我想这就是解决问题的方法。 我试过: <style> #loading { width: 30%; height: 30%; position: absolute; left: 25%; top: 25%; background-color: green; line-height: 5; text-a
<style>
#loading {
width: 30%;
height: 30%;
position: absolute;
left: 25%;
top: 25%;
background-color: green;
line-height: 5;
text-align: center;
display: none;
}
</style>
<script>
$('#formularz').on("submit", function() {
$("#loading").show();
});
</script>
<h1>Dodaj numery do przedzwonienia</h1>
<h3>Wybierz zamówienie, którego numery chcesz przedzwonić:</h3>
<div class="order-form" id="formularz">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'id')->dropDownList(ArrayHelper::map(Order::find()->all(), 'id', 'id')) ?>
<?= Html::submitButton("Przedzwoń", ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
</div>
<div id="loading">
Ładowanie trwa...
</div>
#装载{
宽度:30%;
身高:30%;
位置:绝对位置;
左:25%;
最高:25%;
背景颜色:绿色;
线高:5;
文本对齐:居中;
显示:无;
}
$('#formularz')。关于(“提交”,函数(){
$(“#加载”).show();
});
普泽德沃尼尼亚数字酒店
Wybierz zamówienie,którego numery chcesz Przedzonić:
Ładowanie trwa。。。
但是没有工作。
元素没有提交
事件。提交事件适用于
。因此,您的表单开始标签应为:
<form id="formularz" .....>
这意味着在提交div#formularz
内的一些
时,您的事件将发生
我不熟悉Yii,但可以尝试以下方式:
ActiveForm::begin([
'id' => 'formularz',
]);
然后检查生成的html。您可能需要使用JSExpression,还需要添加console.log以查看它是否触发 如果您在浏览器上点击F12并检查控制台。。。希望能有帮助
<?php
// this goes on top of file to other uses right after namespace
use yii\web\JsExpression;
?>
<style>
#loading {
width: 30%;
height: 30%;
position: absolute;
left: 25%;
top: 25%;
background-color: green;
line-height: 5;
text-align: center;
display: none;
}
</style>
<?php
// you might want to use JSExpression and check if it triggers
$this->registerJs("
$('#formularz').on('submit', function() {
$('#loading').show();
console.log('loading...');
});
"); ?>
<h1>Dodaj numery do przedzwonienia</h1>
<h3>Wybierz zamówienie, którego numery chcesz przedzwonić:</h3>
<!-- you can not use same id twice -->
<div class="order-form" id="formularz-div">
<?php $form = ActiveForm::begin([
'id' => 'formularz',
]); ?>
<?= $form->field($model, 'id')->dropDownList(ArrayHelper::map(Order::find()->all(), 'id', 'id')) ?>
<?= Html::submitButton("Przedzwoń", ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
</div>
<div id="loading">
Ładowanie trwa...
</div>
#装载{
宽度:30%;
身高:30%;
位置:绝对位置;
左:25%;
最高:25%;
背景颜色:绿色;
线高:5;
文本对齐:居中;
显示:无;
}
好的,但我使用的是Yii,我从这样的表单开始:$form=ActiveForm::begin()代码>,那么我可以把它放在哪里?我不能两次开始一个表格,我试过了,没有结果。我还试图找到由Yii生成的表单的id,但它一点也并没有改变。
<?php
// this goes on top of file to other uses right after namespace
use yii\web\JsExpression;
?>
<style>
#loading {
width: 30%;
height: 30%;
position: absolute;
left: 25%;
top: 25%;
background-color: green;
line-height: 5;
text-align: center;
display: none;
}
</style>
<?php
// you might want to use JSExpression and check if it triggers
$this->registerJs("
$('#formularz').on('submit', function() {
$('#loading').show();
console.log('loading...');
});
"); ?>
<h1>Dodaj numery do przedzwonienia</h1>
<h3>Wybierz zamówienie, którego numery chcesz przedzwonić:</h3>
<!-- you can not use same id twice -->
<div class="order-form" id="formularz-div">
<?php $form = ActiveForm::begin([
'id' => 'formularz',
]); ?>
<?= $form->field($model, 'id')->dropDownList(ArrayHelper::map(Order::find()->all(), 'id', 'id')) ?>
<?= Html::submitButton("Przedzwoń", ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
</div>
<div id="loading">
Ładowanie trwa...
</div>