Javascript 使用get方法在表单中创建随机url
我试图在脚本中创建一个随机URL 我想随机选择此url:Javascript 使用get方法在表单中创建随机url,javascript,jquery,Javascript,Jquery,我试图在脚本中创建一个随机URL 我想随机选择此url: action="https://www.google.com/search?q=" action="https://www.google.com/search?q=" action="https://www.bing.com/search?q=" action="https://search.yahoo.com/search?p=" 与: action="https://www.google.com/search?q=" actio
action="https://www.google.com/search?q="
action="https://www.google.com/search?q="
action="https://www.bing.com/search?q="
action="https://search.yahoo.com/search?p="
与:
action="https://www.google.com/search?q="
action="https://www.google.com/search?q="
action="https://www.bing.com/search?q="
action="https://search.yahoo.com/search?p="
Html:
<form id="search-form" target="_blank" method="get" action="https://www.google.com/search?q=">
<input id="aaa" placeholder="..." name="url" type="text">
<input class="bbb" value="search" type="submit">
</form>
谢谢,
函数getRandomUrl(){
常量URL=[
'https://www.google.com/search?q=',
'https://www.bing.com/search?q=',
'https://search.yahoo.com/search?p='
]
返回URL[Math.floor(Math.random()*url.length)]
}
函数随机化(){
const url=getRandomUrl()
const$form=document.getElementById('search-form')
$form.setAttribute('action',url)
}
随机化()
随机