<html>
<head>
</head>
<body>
<div id = "txt">
<form>
<input type="submit" value="submit" />
</form>
ddss
</div>
<script language="JavaScript">
document.getElementById("txt").innerHTML = document.getElementById("txt").innerHTML.replace(/(submit)/gi,"<a href=http://www.baidu.com><font color=green>$1</font></a>");
</script>
</body>
</html>
不能使用jquery操作文档不是太方便。查找元素很难写。
下面给你个不用js的版本。
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.button {
display: block;
width:120px;
text-align:center;
border: 1px solid red;
background-color: white;
color:red;
text-decoration:none;
padding:3px;
}
</style>
</head>
<body>
<a class="button" href="baidu.com">去百度</a>
</body>
</html>
用jquery作万能跳转。代码如下
<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="../jquery/jquery-1.11.1.min.js"></script>
</head>
<body>
<button data-href="http://www.baidu.com">去百度</button>
<span data-href="http://taobao.com">去淘宝</span>
<script type="text/javascript">
$("[data-href]").on('click', function (event) {
window.location.href = $(this).attr("data-href");
});
</script>
</body>
</html>
你的是提交按钮。加链接了你是要提交表单还是转到链接?这种要求原本就是冲突的,做好描述清楚你要干嘛