您现在的位置是:首页 > 电脑技术查询 > web开发

js怎样为href赋值?解决办法

编辑:chaxungu时间:2022-10-02 23:18:01分类:web开发

js怎样为href赋值?
js怎样为href赋值?
可以这样的吗?
<form action="" method="post" name="myform">
<a href="" name=links>点击</a>
</form>
<script>
document.myform.links.href="http://www.google.com"
</script>

------解决方案--------------------
HTML code<form action="" method="post" name="myform" ><a href="" id=links >点击 </a ></form ><script >document.getElementById("links").href="http://www.google.com";</script >
------解决方案--------------------
JScript codewindow.onload=function(){ var theLink=document.getElementById("myLink"); theLink.onmouseover=function() { this.setAttribute("href","google.com"); this.innerHTML="link to google.com"; }}