【问题标题】:Load page without refresh with label form使用标签表单加载页面而不刷新
【发布时间】:2013-12-15 18:09:01
【问题描述】:

我正在尝试在复选框的页面真实列表上加载结果

我这里有这个代码 - http://css-tricks.com/dynamic-page-replacing-content/

我想做这样的事情:

$("#form_id").delegate("input", "click", function() {
    window.location.hash = $(this).attr("href");
    return false;
});

但我在网址的末尾 - #undefined

我的表格是:

<form name="search" action="" method="get" id="search_form">

    <div class="fluid">
      <div style="padding-right: 5px; ">        

                         <label> computer <input class="chkd" type="checkbox" checked="checked" name="category[]" value="computers"> </label>
                         <label> computer <input class="chkd" type="checkbox" checked="checked" name="category[]" value="computers1"> </label>
                         <label> computer <input class="chkd" type="checkbox" checked="checked" name="category[]" value="computers2"> </label>

   </div> </div>
</form>

有什么想法吗?

【问题讨论】:

  • 你的 HTML 是什么? input 没有 href 属性。

标签: javascript ajax forms url


【解决方案1】:

原文用途:

 $("nav").delegate("a", "click", function() {
        window.location.hash = $(this).attr("href");
        return false;
    });

表示它引用nav 中的a 标签。但是在您的代码中,您似乎正在尝试获取inputhref。这是不可能的。

试试这个:

window.location.hash = $("nav a").attr("href");

代替:

window.location.hash = $(this).attr("href");

只要参考右边的a标签。

【讨论】:

  • @Yaakov 你想达到什么目的?用复选框的值更新哈希?那么这可能会有所帮助:window.location.hash = $(this).val();
  • 另外,用$("#form_id")代替$("#search_form")
  • 我需要将字段的“name=value”添加到url,比如= $(this).val() = $(this).name()
  • 请举例说明您想做什么?你想将hash 添加到像#name=computer1 这样的网址吗?
  • example-index.php?&category[]=computers&category[]=computers1
猜你喜欢
  • 2019-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
  • 2020-04-03
  • 1970-01-01
  • 2020-12-12
  • 2021-01-07
相关资源
最近更新 更多