从 $.post 请求结果更改表单
这是我的困境,我有一个页面,顶部有一个表格。该表单包含多个具有相同名称的复选框:“主题”。每次我勾选或取消勾选一个或多个复选框时,它都会使用 $.post jquery 请求将结果页面加载到 div 中,如下所示:
$.post("index-main-list.php", $("#selectors").serialize(), function(data){
$('#main-list').html(data); });
我的表单 id 为“选择器”,结果加载到“主列表”div 中。 到目前为止,所有这些都运行良好。
#main-list 中加载的页面结果包含与用户选择的主题相对应的文章列表。
但在此列表中,每篇文章都有一个指向其特定主题的链接,我希望这些链接执行的操作是取消选中页面上表单中的所有框,并仅勾选相应的框,从而触发新的执行$.post 请求,因此仅加载与用户选择的主题相对应的文章。
通过使用类似的东西:
$('#selectors')[0].reset();
$('input[id=topic]').attr('checked', true);
但由于某种原因,我似乎无法更改 #selectors 表单中的任何内容,任何人都可能知道为什么?谢谢!
here's my dilemma, I have a page, with a form on top. This form contains multiple checkboxes with the same name: "Topic". Each time I tick or untick one or more checkboxes it loads the resulting page in a div by using a $.post jquery request, like this:
$.post("index-main-list.php", $("#selectors").serialize(), function(data){
$('#main-list').html(data); });
my form id being "selectors" and the result being loaded in the "main-list" div.
So far, all of this works fine.
The page result loaded in the #main-list contains a list of articles corresponding to the topic the user chooses.
But in this list, every article has a link to his specific topic, what I would want those links to do, is to untick all boxes in the form that is on the page, and tick only the corresponding box, therefore triggering a new execution of the $.post request and therefore loading only the articles corresponding to the topic the user chose.
By using something like :
$('#selectors')[0].reset();
$('input[id=topic]').attr('checked', true);
But for some reason, I can't seem to change anything in the #selectors form, anyone might have an idea why? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在寻找这样的东西吗?
另外,如果
#selectors
是您的表单,那么这将更加具体并且性能更好:Are you looking for something like this?
Also, if
#selectors
is your form, then this will be more specific and perform a bit better: