jQuery;检测选择框是否已更改或被选中
我有一个流程可以检测选择框是否更改,如果确实更改,则 div 中的内容会重新加载。
我意识到,当提交表单并出现错误时,选择框应该在提交之前选择选项,选择。如果是这种情况,div 需要重新加载正确的内容。
我当前检测更改并根据 id 重新加载内容的方法如下:
//On drop-down change
$("#tiers").change(function() {
var selectedId = $(this).val();
if(selectedId != 0) {
container = new Array();
var container = $('#tier'+selectedId+' a.removePanel').map(function() {
var match = this.id.match(/\d+$/);
return match ? match[0] : null;
}).get();
loadContent(container);
} else {
$('#panels').html('<p class="error">Please select a Tier from the drop-down in order to assign Panels.</p>');
}
});
EDIT#1
通过简单地检测 $_post 变量是否有内容,使用 PHP 和 Smarty 设法做到这一点。
I have a process in place which detects if a select box is changed, if it does get changed, the content in a div reloads.
I've realised that when the form is submitted and has errors, the select box should have the option selected prior to submit, selected. If this is the case, the div needs to reload with the correct content.
My current method for detecting a change and reloading content based on id's is as follow:
//On drop-down change
$("#tiers").change(function() {
var selectedId = $(this).val();
if(selectedId != 0) {
container = new Array();
var container = $('#tier'+selectedId+' a.removePanel').map(function() {
var match = this.id.match(/\d+$/);
return match ? match[0] : null;
}).get();
loadContent(container);
} else {
$('#panels').html('<p class="error">Please select a Tier from the drop-down in order to assign Panels.</p>');
}
});
EDIT#1
Managed to do this using PHP and Smarty by simply detecting if the $_post variable had content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前做过很多次,在回发后,只需发布所选复选框的所有 id 的数组,然后将数组中包含 ID 的复选框设置为 selected 。
I did this many times before, after your postback just post an array of all the id's of the checkboxes that are selected, and then set the checkboxes with the ID's in the array to selected .