I do have a input['text']
field to insert date and also have a dropdown
for select category.
我有一個輸入['text']字段來插入日期,還有一個選擇類別的下拉列表。
When changing the date input field I want to make the page reload with attaching date and category values in the URL.
更改日期輸入字段時,我想通過在URL中附加日期和類別值來重新加載頁面。
NOTE: Here I want to attach category value if it is not empty.
注意:這里我想附加類別值,如果它不是空的。
This is how I tried it. But it doesn't work for me.
這就是我嘗試的方式。但它對我不起作用。
$("#date").change(function() {
var c = $("#category").val();
var d = $(this).val();
if(c.length === 0 ) {
var cat = "$cat="+c;
} else {
var cat;
}
location.href="?p=attendance&todate="+d.add(cat);
})
This is the output, when category ID is not empty.
當類別ID不為空時,這是輸出。
?p=attendance&todate=2016-08-04undefined
Can anybody help me to fix my problem? Thank you.
任何人都可以幫我解決問題嗎?謝謝。
0
You could try this approach. Put only what you have.
你可以嘗試這種方法。只放你所擁有的。
$("#date").change(function() {
var url = '';
var c = $("#category").val();
var d = $(this).val();
if(c.trim().length) { url+='&cat='+c }
if(d.trim().length) { url+='&todate='+d }
location.href="?p=attendance"+url;
})
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/08/05/7254470ca2eddac2c512928251b0880.html。