我有一個文本字段和輸入類型提交。當我點擊提交按鈕時,我應該得到一個與輸入字段相關的網址。但我得到Uncaught TypeError: undefined is not a function
。這裏是我的代碼,以解釋越多越好:爲什麼連接兩個字符串會產生錯誤?
<script>
$(document).ready(function(e) {
$('#search_btn').click(function() {
console.log($('#thisiswhatineed').val()); // this is working perfectly
console.log("<?php echo BASE_URL; ?>/ads/search/"); // this is also working perfectly
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" . $('#thisiswhatineed').val();
console.log(url_to_go); // this is not working and giving me the error mentioned above
});
});
</script>
在javascript中連接是用a +而不是a來完成的。像php – JohannesB
@Rsauxil,你應該補充說,作爲答案:)(不要忘了,也會打敗你) –
是的,也許我應該,但無論如何,問題的解決,所以誰在乎現在:P – JohannesB