开发者社区> 问答> 正文

javascript onclick 无法触发其引用的自定义函数

 <!DOCTYPE html>
<html>
<head>
<title>文章管理</title>
<link href="/blog/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
    font-family: Georgia, "Times New Roman", Times, serif;
    color: #555;
    background-color: #f9f9f9;
}

h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 {
    margin-top: 0;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: normal;
    color: #333;
}

header {
    background-color: #428bca;
    -webkit-box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1);
    box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1);
}

.resume-navbar-brand {
    font-weight: 500;
    color: #cdddeb;
    background-color: #428bca;
}

.resume-navbar-brand:hover, .resume-navbar-brand:focus {
    color: #fff;
}

.resume-navbar-right li a {
    color: #cdddeb;
}

.resume-navbar-right li a:hover, .resume-navbar-right li a:focus {
    background-color: #cdddeb;
    color: #428bca;
}

.resume-button {
    background-color: #428bca;
    color: #cdddeb;
}

.resume-button:hover, .resume-button:focus {
    background-color: #f9f9f9;
    color: #555;
}

.resume-after-icon {
    margin-right: 5px;
}

.resume-techpercent {
    height: 30px;
}

.well {
    background-color: #cdddeb;
}

.resume-subtitle {
    background-color: #428bca;
    color: #cdddeb;
}

footer {
    padding: 16px 0;
    color: #cdddeb;
    text-align: center;
    background-color: #428bca;
    border-top: 1px solid #e5e5e5;
}

footer a {
    color: #cdddeb;
}
/*导航样式控制*/
.navbar-default {
    background-color: #428bca;
    border-color: #cdddeb;
}

.navbar-default .navbar-brand {
    color: #cdddeb;
}

.navbar-default .navbar-nav>li>a {
    color: #cdddeb;
}

.navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>li>a:focus
    {
    background-color: #cdddeb;
    color: #555;
}
/*右上侧小button样式控制*/
.navbar-default .navbar-toggle {
    background-color: #cdddeb;
}

.navbar-default .navbar-toggle:visited {
    background-color: #cdddeb;
}

.navbar-default .navbar-toggle:hover, .navbar-default .navbar-toggle:focus
    {
    background-color: #DFEAF8
}

.navbar-default .navbar-toggle .icon-bar {
    background-color: #428bca;
}

.navbar-default .navbar-collapse, .navbar-default .navbar-form {
    border-color: #cdddeb;
}

.navbar-default .navbar-toggle {
    border-color: #cdddeb;
}
</style>

<script type="text/javascript" src="/blog/script/jquery-1.12.1.min.js"></script>
<script type="text/javascript" src="/blog/script/bootstrap.min.js"></script>
<script>
function testButton(){
    alert("click");
}

function editArticle(articleId){
    window.location.href="/blog/article/editArticle.do?articleId="+articleId+"&randomCode="Math.random();
}

function deleteArticle(elem, articleId) {
    $.ajax({
        type:"POST",
        url:"/blog/article/deleteArticle.do",
        data:"articleId="+articleId,
        success:function(data){
            if(data==true){
                $(elem).parent().parent().remove();
                alert("文章删除成功");
            }
        }
    })
}

$(function(){

    $("#articleCatalog_createArticle").click(function(){
        window.location.href = "/blog/article/addArticle.do";
    })


});



</script>

</head>
<body>
    <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target="#navbar" aria-expanded="false"
                    aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span
                        class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">切换英文</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="javascript:void(0)">测试1</a></li>
                    <li><a href="javascript:void(0)">测试2</a></li>
                    <li><a href="javascript:void(0)">测试3</a></li>
                </ul>
            </div>
        </div>
        <!--/.nav-collapse -->
    </nav>
    <div class="container">
        <div class="row">
            <div class="col-lg-7 col-md-7 col-sm-7">
                <nav class="navbar navbar-default" role="navigation">
                    <div class="btn-group pull-right">
                        <button id="articleCatalog_createArticle" type="button" class="btn btn-success">新建</button>
                    </div>
                </nav>
                <button onclick="testButton()">test</button>
                <ul class="list-group">

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=3822ff5c60d1428eb01f0bc9166bed9b">y</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'3822ff5c60d1428eb01f0bc9166bed9b')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=42cd043b183c4454844544733ea23104">i</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'42cd043b183c4454844544733ea23104')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=5ad13b9e06fb459189142352d03f4f98">o</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'5ad13b9e06fb459189142352d03f4f98')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=60b719bdf82444ce873f13182445ad10">x</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'60b719bdf82444ce873f13182445ad10')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=6db4a5087a46425eb301522c6f76137c">w</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'6db4a5087a46425eb301522c6f76137c')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=74fa5fc2dfee4290986a3397a7f1d397">f</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'74fa5fc2dfee4290986a3397a7f1d397')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=85b0a832f3564ef388c817e509098578">l</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'85b0a832f3564ef388c817e509098578')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=8a9cb5a0196f4cc0a562067ceb80be4d">j</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'8a9cb5a0196f4cc0a562067ceb80be4d')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=92624b6422fa423490aa179e562f97a3">v</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'92624b6422fa423490aa179e562f97a3')">删除</button>
                            </div></li>

                        <li class="list-group-item"><a href="/blog/article?action=showArticle&articleId=9789a998ff894e48a080b86965837d98">c</a>
                            <div class="pull-right">
                                <button onclick="testButton()">test</button>
                                <button onclick="alert('click');">编辑</button>
                                <button onclick="deleteArticle(this,'9789a998ff894e48a080b86965837d98')">删除</button>
                            </div></li>


                </ul>

                <nav>
                    <ul class="pagination">
                        <li><a
                            href="/blog/article/showCatalogue.do?pageNum=1">首页</a>
                        </li>
                        <li><a
                            href="/blog/article/showCatalogue.do?pageNum=1">上一页</a>
                        </li>

                            <li><a
                                href="/blog/article/showCatalogue.do?pageNum=1">1</a>
                            </li>

                            <li><a
                                href="/blog/article/showCatalogue.do?pageNum=2">2</a>
                            </li>

                        <li><a
                            href="/blog/article/showCatalogue.do?pageNum=2">下一页</a>
                        </li>
                        <li><a
                            href="/blog/article/showCatalogue.do?pageNum=2">末页</a>
                        </li>
                    </ul>
                </nav>
            </div>
            <div class="col-lg-5 col-md-5 col-sm-5">
                <div class="well">


                </div>
            </div>
        </div>
    </div>
    <footer>

    </footer>

<script type="text/javascript">

</script>
</body>
</html>
此处onclick="testButton()"无法执行

展开
收起
小旋风柴进 2016-03-16 16:49:15 4065 0
1 条回答
写回答
取消 提交回答
  • 自定义函数就是说自己写的函数,只有自己调用,或是自己共享给别人后别人才可以调用的。也可以理解为私有函数。 function a(){alert(1)};  //定义一个函数,名字是a。 函数调用,就是让函数执行。 a();  //函数名字后面加一对小括号就可以执行了, 页面中将弹出一个 

    答案来源于网络

    2019-09-23 12:59:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
JavaScript函数 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载