点击button获取text内容并改变样式的js实现

2019-12-21,,

需求:点击button获得input框中选中的内容,让选中的内容变红,

实现:代码如下

<!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>

效果:

您可能感兴趣的文章:

  • javascript插入样式实现代码
  • JavaScript插入动态样式实现代码
  • ExtJS自定义主题(theme)样式详解
  • jsp页面中插入css样式的三种方法总结
  • js动态修改整个页面样式达到换肤效果
  • jquery mobile页面跳转后样式丢失js失效的解决方法
  • js实现class样式的修改、添加及删除的方法
  • 使用javascript插入样式

《点击button获取text内容并改变样式的js实现.doc》

下载本文的Word格式文档,以方便收藏与打印。