我有一个input
,应该添加一个clicked
类的另一个元素的ID为#zip
点击。下面是代码:如何添加一个类到一个元素,当我点击与jquery不同的元素
$('#billing_zip').click(function() {
$('#zip').addClass('clicked');
});
#zip {
color: #444;
font-style: italic;
position: absolute;
top: 8px;
left: 35px
}
.clicked {
display: none;
}
<div class="chkField">
<label for="billing_zip">Zip</label>
<input type="text" onchange="clearContent(this);check_address('billing');" class="txtBoxStyle hasPlaceholder" tabindex="10" size="10" value="" id="billing_zip" maxlength="15" name="billing_zip">
<!--START: req_billing_zip-->
<img width="12" height="12" alt="" src="assets/templates/common/images/error2.gif">
<!--END: req_billing_zip-->
<div class="clear"></div>
<div id="zip">zip</div>
</div>
我不知道为什么上面的jQuery不工作。
至于我可以看到你的代码工作得精细。 “点击”类正在得到应用。 http://jsfiddle.net/8L5qdeu7/ – 2014-12-05 04:30:46
不要忘记把你的jQuery代码包装在'$(document).ready(function(){//你的jquery代码//});' – 2014-12-05 04:31:27
add id ='billing_zip '在标签。您将billing_zip声明为自定义属性(for)。但是你选择它作为id。 – zanhtet 2014-12-05 04:32:19