开发者社区> 问答> 正文

按钮添加超级链接,应该怎么改改,或者超链接是按钮样式

 <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>

展开
收起
小旋风柴进 2016-03-17 13:34:54 2002 0
1 条回答
写回答
取消 提交回答
  • 不能使用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>
    2019-07-17 19:05:12
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载