Home >Web Front-end >HTML Tutorial >How to make the border color of the text box turn green when clicked_html/css_WEB-ITnose

How to make the border color of the text box turn green when clicked_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:02:312162browse



Reply to discussion (solution)

<script src=/scripts/jquery-1.8.3.min.js></script><script>$(function() {  $(":text").focus(function() {    $(this).css('border-color', '#0f0');  }).blur(function() {    $(this).css('border-color', '');  })});</script><input type=text><input type=text><input type=text><input type=text>

Is there any other way to write it? !

Just use a css pseudo-class
input:focus {
border-style: solid;
border-color: #339933;
}

input:focus{	border-style:solid;	border-color:#339933}

input:focus{	border-style:solid;	border-color:#339933}


How to implement it using div class? !


input:focus{	border-style:solid;	border-color:#339933}


How to implement it using div class? !
Using jQuery:
<style type="text/css">	.green{		border-style:solid;		border-color:#339933	}</style>$("#你的input的ID").focus(	function(){		$("#你的div的ID").addClass("green");			}).blur(	function(){		$("#你的div的ID").removeClass("green");		});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn