chila

导航

jquery---通过输入框筛选,并通过URL参数获取将所选内容填入input框中

<div class="row">
<div class="col-sm-7">
<div class="input-group mb-3">
{% if filters %}
{% for f in filters %}
{% if "date" in f.name %}
<input type="text" name={{ f.name }} class="form-control pick-date"
placeholder="&#xf073;&nbsp {{ f.placeholder }}" autocomplete="off">
{% else %}
<input type="text" name={{ f.name }} class="form-control"
placeholder={{ f.placeholder }} autocomplete="off">
{% endif %}
{% endfor %}
<input type="hidden" name="source" value={{ source }}>
{% if 'hidden' in request.GET %}
<input type="hidden" name="hidden" value="1">
{% endif %}
<button class="btn btn-primary" type="submit" id="chaxun">查 询</button>
{% endif %}
</div>
</div>
</div>

<script>
$('.pick-date').datepicker({
format: "yyyy-mm-dd",
maxViewMode: 1,
language: "zh-CN",
defaultDate : new Date()
});

$("input:text", document.forms[0]).each(function(){
$(this).val(getUrlParam(this.name))
});

function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null)
return decodeURI(r[2]);
return null; //返回参数值
}

</script>

posted on 2022-01-12 16:23  chila  阅读(185)  评论(0编辑  收藏  举报