我有一個textarea文本「ez.aaaa.value」我想輸入文本,當我選擇選項時,自動重定向到google.com/search?tbm=isch & q = +((value textarea))如何在選項選擇中添加值?
例子:
........
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value">google search</option>
........
我有一個textarea文本「ez.aaaa.value」我想輸入文本,當我選擇選項時,自動重定向到google.com/search?tbm=isch & q = +((value textarea))如何在選項選擇中添加值?
例子:
........
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value">google search</option>
........
這應該這樣做。
location.href
是你會用來鏈接的。
this
指的是select和selectedIndex
返回所選選項的編號。
var sel = document.getElementById('mysel'),
query = document.getElementById('myquery');
sel.addEventListener('change' , function() {
console.log(this.options[this.selectedIndex].value + query.value);
// this would be how to link below
// location.href = this.options[this.selectedIndex].value + query.value;
});
<input type='text' id="myquery">
<select id="mysel">
<option>SELECT ONE</option>
<option value="http://google.com?q=">google</option>
<option value="http://bing.com?q=">bing</option>
</select>
在我的代碼中刪除位於location.href前面的//。 – creativekinetix
與ID添加select
您option
的外面再嘗試這種方式
JS
var e = document.getElementById("select-menu");
var strUser = e.options[e.selectedIndex].value;
console.log(strUser);
HTML
<select id="select-menu">
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value">google search 1</option>
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value" selected="selected">google search 2</option>
</select>
謝謝,我怎麼能自動重定向鏈接到「href ='http://www.google.com/search?tbm = isch&q ='+ ez.aaaa.value」 – moon90
@ moon90使用'window.location = strUser;在相同的標籤中重定向。 –
1)使用
這是什麼選擇?對於 –
解釋你的問題 –
你試過'$(「#myselect option:selected」).text(); (或val())' –