>  기사  >  웹 프론트엔드  >  텍스트 내용을 가져오고 style_javascript 기술을 변경하기 위해 버튼을 클릭하는 Node.js 구현

텍스트 내용을 가져오고 style_javascript 기술을 변경하기 위해 버튼을 클릭하는 Node.js 구현

WBOY
WBOY원래의
2016-05-16 16:36:531771검색

요구사항: 버튼을 클릭하면 입력창에 선택한 내용이 들어가고 선택한 내용이 빨간색으로 변합니다.

구현: 코드는 다음과 같습니다

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="content-type" content="text/html;charset=utf-8">

<title>Test</title>

<style type="text/css">

div{

display: none;

}

</style>

</head>

<body>

<input type="text" id="txt" value="" /> 

<input type="button" value="获取文本框内的值" id="btn" onclick="getText();"/>

<div id="showText">

</div>

<script type="text/javascript">

function getText () {

var showText = document.getElementById("showText");

showText.style.display = "block";

showText.style.color = "red";

showText.innerHTML=document.getElementById("txt").value;

}

</script>

</body>

</html>

효과:

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.