admin管理员组文章数量:1391977
<input type="text" name="my_sld" style="width: 55%" value="">
<br />
<select name="my_tld" style="width: 20%">
<option value="" label=""> </option>
<option value="net" label="net"> </option>
<option value="org" label="org"> </option>
</select>
<script>
var sld = my_sld();
var tld = my_tld();
var domain = sld + tld;
</script>
<button go to = / + domain + >
how to make my_sld + my_tld go to mysite when i click the button via javascript?
for example =
<input type="text" name="my_sld" style="width: 55%" value="">
<br />
<select name="my_tld" style="width: 20%">
<option value="" label=""> . </option>
<option value="net" label="net"> </option>
<option value="org" label="org"> </option>
</select>
<script>
var sld = my_sld();
var tld = my_tld();
var domain = sld + tld;
</script>
<button go to = http://example./check/ + domain + >
how to make my_sld + my_tld go to mysite when i click the button via javascript?
for example = http://example./check?domain=thedomainname
Share Improve this question edited Nov 19, 2015 at 20:09 Petr Felzmann 1,3134 gold badges20 silver badges39 bronze badges asked Nov 19, 2015 at 19:37 Selakarweb di siniSelakarweb di sini 111 silver badge3 bronze badges 2-
Try looking into
window.location
. You may have to have your button call a javascript function through onclick, which then sets the location. – Nate Young Commented Nov 19, 2015 at 19:41 - Give to the input text and to the select an id attribute then load the value with jquery. You can append that value to the url – Antonio Commented Nov 19, 2015 at 19:44
2 Answers
Reset to default 7You should do like this..
First provide any ID to button :
<button id=“test” value=“click">
Then in javascript you should do like:
<script>
$("#test").click(function(){
var sld = my_sld();
var tld = my_tld();
var domain = sld+tld;
window.location.href="http://example./check?domain="+domain;
})
</script>
<script>
function redirect() {
window.location = 'http://example./check/' + sld + tld;
}
</script>
<button onclick='redirect();'>
or with unobtrusive and still pure javascript
<button id='redirect'>
<script>
document.getElementById('redirect').onclick = function() {
window.location = 'http://example./check/' + sld + tld;
};
</script>
本文标签: htmlpassing var to url when click button via javascriptStack Overflow
版权声明:本文标题:html - passing var to url when click button via javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744694169a2620174.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论