小白求问:用input给href赋值的js怎么写,js高手留步?
<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>用input给href赋值的问题</title></head>...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用input给href赋值的问题</title>
</head>
<body>
<input type="text" id="cityname" value="城市名称">
<input type="button" id="openweb" value="搜索" onclick="geturl()">
<a href="#" id="newurl" tager="_blank"></a>
</body>
<script type="text/javascript">
function geturl() {
var bianliang = "document.getElementById('cityname').value";
var newurl = "'http://map.qq.com/m/place/result/city='+bianliang+'&word='+bianliang+'&bound=&cpos=&searchBar='";
document.location = newurl;
}
</script>
</html> 展开
<html>
<head>
<meta charset="utf-8">
<title>用input给href赋值的问题</title>
</head>
<body>
<input type="text" id="cityname" value="城市名称">
<input type="button" id="openweb" value="搜索" onclick="geturl()">
<a href="#" id="newurl" tager="_blank"></a>
</body>
<script type="text/javascript">
function geturl() {
var bianliang = "document.getElementById('cityname').value";
var newurl = "'http://map.qq.com/m/place/result/city='+bianliang+'&word='+bianliang+'&bound=&cpos=&searchBar='";
document.location = newurl;
}
</script>
</html> 展开
2个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用input给href赋值的问题</title>
<script type="text/javascript">
function geturl() {
var bianliang = document.getElementById('cityname').value;
location.href = 'http://map.qq.com/m/place/result/word='+escape(encodeURI(bianliang));
}
</script>
</head>
<body>
<input type="text" id="cityname" value="" placeholder="城市名称">
<input type="button" id="openweb" value="搜索" onclick="geturl()">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>用input给href赋值的问题</title>
<script type="text/javascript">
function geturl() {
var bianliang = document.getElementById('cityname').value;
location.href = 'http://map.qq.com/m/place/result/word='+escape(encodeURI(bianliang));
}
</script>
</head>
<body>
<input type="text" id="cityname" value="" placeholder="城市名称">
<input type="button" id="openweb" value="搜索" onclick="geturl()">
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询