我想獲得一個sql查詢運行下拉菜單選擇。以下是我迄今爲止:更改下拉菜單做jQuery的功能和sql查詢
<script>
$('#templateid').change(function(DoUpdateOnSelect) {
$.post('page.edit.php?page_id=(-->Need help in getting this id from the page url<--)&template='+this.options[this.selectedIndex].value);
});
</script>
而且下拉:
<select name="templateid" id="templateid" onchange="DoUpdateOnSelect">
<option >Contact</option>
<option >News</option>
<option >Home</option>
</select>
page.edit.php有它的條件,這將運行SQL查詢,如果它檢測到的頁面ID和模板在URL中。從選擇下拉菜單中,用jquery抓取模板參數值(請讓我知道該部分是否在jquery中設置錯誤)。我無法弄清楚如何從頁面的當前網址抓取page_id參數,並將其插入到函數中,以便page.edit.php?page_id = 1 & template = Home將被正確輸出的URL 。
如果您需要更多信息,請讓我知道。提前致謝。
編輯:基於回答以下:
function querystring(name)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return results[1];
}
$('#templateid').change(function() {
var page_id = querystring('page_id');
var url = '?VIEW=EDITPAGE&linklabel='+page_id+'&template='+(this.options[this.selectedIndex].value);
$.post(url);
});
NO變化正在發生WHEN我進行選擇的下拉菜單
[在JavaScript中獲取查詢字符串值](http:// stackoverf low.com/questions/901115/get-query-string-values-in-javascript) – 2012-02-16 01:37:21
感謝Michael對於這個問題的鏈接,我試着儘可能多地查看它們.. – 2012-02-16 01:47:59