<分区>
标签 javascript jquery html css
<分区>
目前正在为我的大学 COSC 类(class)在我的实验室工作。在实验室中,我应该能够点击一个按钮并且按钮边框应该变成“3px solid green” 这是我目前拥有的:
<html>
<head>
<title>Lab 10</title>
<style type="text/css">
div, p{
width: 600px;
background-color: lightgray;
}
.border_green{
border: 3px solid green;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js">
</script>
<script type="text/javascript>">
$("#b1").click(function(){
$("#b1").attr("Class",".border_green");
});
</script>
</head>
<body>
<input id="b1" classname="button" type="button" value= "If this is clicked, a green solid border of three pixels will be created.">
</html>
最佳答案
您只需要从类名中删除点符号并将您的脚本包装在 ready 方法中,如 Tushar 所建议的 这是 demo 这是更新后的脚本。
$(document).ready(function(){
$("#b1").click(function(){
$("#b1").attr("class","border_green");
});
});
关于javascript - 使用 Jquery 添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33818617/