我想知道是否可以使用按钮而不是href来触发div。
以下是以下示例:
这是当前的div:
<div id="ver" class="modal-block modal-block-primary mfp-hide">
<section class="panel">
<header class="panel-heading">
<h2 class="panel-title">Registration Form</h2>
</header>
<form class="form-horizontal mb-lg" method="POST" novalidate="novalidate">
<div class="panel-body">
<div class="form-group mt-lg">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-9">
<input type="text" name="name" class="form-control" placeholder="Type your name..." required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input type="email" name="email" class="form-control" placeholder="Type your email..." required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">URL</label>
<div class="col-sm-9">
<input type="url" name="url" class="form-control" placeholder="Type an URL..." />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Comment</label>
<div class="col-sm-9">
<textarea rows="5" class="form-control" placeholder="Type your comment..." required></textarea>
</div>
</div>
</div>
<footer class="panel-footer">
<div class="row">
<div class="col-md-12 text-right">
<input type="submit" name="ola" value="Submit">
<button class="btn btn-default modal-dismiss">Cancel</button>
</div>
</div>
</footer>
</form>
</section>
这是我用href:
触发它的方法<a class="modal-with-form btn btn-default" href="#ver">Open Form</a>
这是我尝试的方式:
<a class="modal-with-form btn btn-default" href="#ver?id=$ausenciaid">Open Form</a>
但它不起作用,有一种方法可以使用按钮代替href吗?
答案 0 :(得分:2)
你可以试试这个
<input type="button" onclick="location.href='Your location';" value="Open Form" />
这将为您提供一个按钮,当您点击它时,您将转移/打开您的href
答案 1 :(得分:0)
不太推荐的内联方式:
<button onclick="location.href='Your location';"> Open Form" </button>
OR
附加活动&amp;使用javascript触发:
<button type="button" id="mybutton" >Open Form </button>
<script>
document.getElementById("mybutton").addEventListener("click", function(){
window.location.href = <input type="button" onclick="location.href='Your location';
});
</script>