关于A标签href和click调用js改变href值的问题

dongzhan7 2010-01-21 10:25:50
a标签中href=“url?a=”,id=“abc” 通过onclick事件执行一个js,获取a的参数,改变href的值打开一个新的页面,js如下: var ddl = document.getElementById("ddl");
var id = ddl.options[ddl.selectedIndex].text;
var href = document.getElementById("abc").href;
href=href+id;
document.getElementById("abc").href=href;
比如ddl的值为15,点击a标签后,href就为“url?a=15”
当我改变ddl的值为17,17是在“url?a=15”的基础上添加17,即为“url?a=1517”
我怎么才能让每次改变ddl值后,保证点击a标签是“url?id=‘ddl的值’”
...全文
2972 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
duwa789 2010-01-22
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script language="javascript">
function Go()
{
document.location.href = "your_address?your_parameter=" + document.getElementById("mySelect").value;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<select id="mySelect">
<option value="1">Go home</option>
<option value="2">Call girl friend</option>
</select>
</div>
<div>
<input type="button" value="Click me" onclick="Go();" />
</div>
</form>
</body>
</html>
veardn 2010-01-22
  • 打赏
  • 举报
回复
<script>
function go(){
var ddl = document.getElementById("ddl");
var id = ddl.options[ddl.selectedIndex].text;
var url="你的url的前缀";
window.location.href=url+id;
}
</script>
<a onclick="go()">
KK3K2005 2010-01-22
  • 打赏
  • 举报
回复
var href = document.getElementById("abc").href.split('?')[0]+'a=';
浴火_凤凰 2010-01-22
  • 打赏
  • 举报
回复
感觉楼主的好像已经出来了
friendly_ 2010-01-21
  • 打赏
  • 举报
回复
在下拉列表ddl的onchange事件中,执行你的js代码,改变a 的href
donet_expert 2010-01-21
  • 打赏
  • 举报
回复
那你每次改变ddl值后
var prehref = "Http://...url?id=";
var idvalue = document.getElementById("ddl").value;
document.getElementById("abc").href='"prehref""+idvalue+"';

试试,不知道对不对。
草根醉秋意 2010-01-21
  • 打赏
  • 举报
回复
<a href="javascript:void(0)" onclick="goto()" />


function goto(){
var ddl = document.getElementById("ddl");
var id = ddl.options[ddl.selectedIndex].text;
//var href = document.getElementById("abc").href;
//href=href+id;
//document.getElementById("abc").href=href;
var href="url?a="+id;
window.location = href;
}

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧