【发布时间】:2016-04-12 22:16:36
【问题描述】:
我有这个代码:
$('.bidbutton').on( "click", function() {
$('.addOffer').hide();
$('.preko').show();
var i = $(this).attr('klik');
$('.i'+i).hide();
$('.j'+i).show();
});
现在,当我单击 jquery 时,会将我带到页面顶部,但我需要留在原处。
我试试
$('.bidbutton').on( "click", function() {
$('.addOffer').hide();
$('.preko').show();
var i = $(this).attr('klik');
$('.i'+i).hide();
$('.j'+i).show();
evt.preventDefault();
});
但不工作... 如何解决这个问题?
问题更新:
<div class="row preko i2" index="2" style="border-bottom-width: 5px; border-bottom-style: solid; border-bottom-color: rgb(255, 255, 255); display: none;">
<div class="col-md-2 col-xs-2" style=" background: #f4f4f4; ">
<h3 class="text-center">20.</h3>
<p class="text-center">Apr</p>
</div>
<div class="col-md-8 col-xs-8 text-center">
<h3>$55</h3>
<p>current bid</p>
</div>
<div class="col-md-2 col-xs-2" style=" margin-top: 25px; "> <a href="#" klik="2" class="btn btn-info btn-lg bidbutton pull-right">Bid Now</a> </div>
</div>
<div class="row addOffer j2" style="display: block;" index="2">
<div class="col-md-2 col-xs-2" style=" background: #f4f4f4; ">
<h3 class="text-center">20.</h3>
<p class="text-center">Apr</p>
</div>
<div class="col-md-10" style="margin-top:10px;">
<form method="POST" action="http://localhost:8888/offers" id="target" accept-charset="UTF-8">
<input type="hidden" name="_token" value="BWSwRnV8diq3QEF5FKcRa0ThWpBODKSMAlwEWZEH"><input name="article_id" type="hidden" value="8"><input name="start" class="hstart" type="hidden" value="04/20/2016 12:00 am"><input name="provera" class="provera" type="hidden" value="522">
<div class="input-group bootstrap-touchspin" style="padding:10px;">
<span class="input-group-btn"><button class="btn btn-default bootstrap-touchspin-down" type="button">-</button></span><span class="input-group-addon bootstrap-touchspin-prefix" style="display: none;"></span><input id="price" type="text" class="form-control price input-lg" name="price" value="55" style="display: block;"><span class="input-group-addon bootstrap-touchspin-postfix" style="display: none;"></span>
<div class="input-group-btn"><button class="btn btn-default bootstrap-touchspin-up" type="button">+</button><button type="submit" class="btn btn-info input-lg okvir">PLACE BID</button></div>
</div>
</form>
</div>
</div>
这是我对 html 代码问题的更新...
【问题讨论】:
-
您需要将
evt传递给您的函数。例如。$('.bidbutton').on( "click", function(evt) {。见event.preventDefault()。如果您包含您的 HTML 以向我们展示一个工作示例,这可能会有所帮助。 -
是的,这就是答案
标签: javascript jquery html click preventdefault