Jquery .val() 无法与 Material Design Bootstrap 一起正常工作
Jquery .val() dont work properly with Material Design Bootstrap
我正在使用 Material 设计 Bootstrap 来设置样式并使用输入占位符做一些不错的事情。
<input id="ConfigName" class="form-control floating-label" placeholder="Name" type="text">
但是如果我尝试 add/change 使用 jquery 输入一些文本,它就无法正常工作。
$('#ConfigName').html("testersres"); // dont work
$('#ConfigName').text("testersres"); // dont work
$('#ConfigName').val("testersres"); //Placeholder and "testersres" is placed on top of each other
我使用的是浮动标签,从上数第二个@here
谁能告诉我哪里出了问题,或者我该如何解决?
这是一张有问题的图片:
赋值的时候,在js中需要把对应的字段classempty
去掉
$('#ConfigName').val("testersres");
$('#ConfigName1').removeClass("form-control empty");
$('#ConfigName1').addClass("form-control");
$('#ConfigName1').val("testersres");
* {
box-sizing: border-box;
}
.header-panel {
background-color: #009587;
height: 144px;
position: relative;
z-index: 3;
}
.header-panel div {
position: relative;
height: 100%;
}
.header-panel h1 {
color: #FFF;
font-size: 20px;
font-weight: 400;
position: absolute;
bottom: 10px;
padding-left: 35px;
}
.menu {
overflow: auto;
padding: 0;
}
.menu,
.menu * {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.menu ul {
padding: 0;
margin: 7px 0;
}
.menu ul li {
list-style: none;
padding: 20px 0 20px 50px;
font-size: 15px;
font-weight: normal;
cursor: pointer;
}
.menu ul li.active {
background-color: #dedede;
position: relative;
}
.menu ul li a {
color: rgb(51, 51, 51);
text-decoration: none;
}
.pages {
position: absolute;
top: 0;
right: 0;
z-index: 4;
padding: 0;
overflow: auto;
}
.pages > div {
padding: 0 5px;
padding-top: 64px;
}
.pages .header {
color: rgb(82, 101, 162);
font-size: 24px;
font-weight: normal;
margin-top: 5px;
margin-bottom: 60px;
letter-spacing: 1.20000004768372px;
}
.page {
transform: translateY(1080px);
transition: transform 0 linear;
display: none;
opacity: 0;
font-size: 16px;
}
.page.active {
transform: translateY(0px);
transition: all 0.3s ease-out;
display: block;
opacity: 1;
}
#opensource {
color: rgba(0, 0, 0, 0.62);
position: fixed;
margin-top: 50px;
margin-left: 50px;
z-index: 100;
}
#source-modal h4 {
color: black;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fezvrasta.github.io/bootstrap-material-design/dist/css/material-fullpalette.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/FezVrasta/bootstrap-material-design/master/dist/js/ripples.js"></script>
<script type="text/javascript" src="https://rawgit.com/FezVrasta/bootstrap-material-design/master/dist/js/material.js"></script>
<input id="ConfigName" class="form-control floating-label" placeholder="Name" type="text">
<br>
<div class="form-control-wrapper">
<input type="text" class="form-control empty" id="ConfigName1">
<div class="floating-label">floating label</div><span class="material-input"></span>
</div>
我正在使用 Material 设计 Bootstrap 来设置样式并使用输入占位符做一些不错的事情。
<input id="ConfigName" class="form-control floating-label" placeholder="Name" type="text">
但是如果我尝试 add/change 使用 jquery 输入一些文本,它就无法正常工作。
$('#ConfigName').html("testersres"); // dont work
$('#ConfigName').text("testersres"); // dont work
$('#ConfigName').val("testersres"); //Placeholder and "testersres" is placed on top of each other
我使用的是浮动标签,从上数第二个@here
谁能告诉我哪里出了问题,或者我该如何解决?
这是一张有问题的图片:
赋值的时候,在js中需要把对应的字段classempty
去掉
$('#ConfigName').val("testersres");
$('#ConfigName1').removeClass("form-control empty");
$('#ConfigName1').addClass("form-control");
$('#ConfigName1').val("testersres");
* {
box-sizing: border-box;
}
.header-panel {
background-color: #009587;
height: 144px;
position: relative;
z-index: 3;
}
.header-panel div {
position: relative;
height: 100%;
}
.header-panel h1 {
color: #FFF;
font-size: 20px;
font-weight: 400;
position: absolute;
bottom: 10px;
padding-left: 35px;
}
.menu {
overflow: auto;
padding: 0;
}
.menu,
.menu * {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.menu ul {
padding: 0;
margin: 7px 0;
}
.menu ul li {
list-style: none;
padding: 20px 0 20px 50px;
font-size: 15px;
font-weight: normal;
cursor: pointer;
}
.menu ul li.active {
background-color: #dedede;
position: relative;
}
.menu ul li a {
color: rgb(51, 51, 51);
text-decoration: none;
}
.pages {
position: absolute;
top: 0;
right: 0;
z-index: 4;
padding: 0;
overflow: auto;
}
.pages > div {
padding: 0 5px;
padding-top: 64px;
}
.pages .header {
color: rgb(82, 101, 162);
font-size: 24px;
font-weight: normal;
margin-top: 5px;
margin-bottom: 60px;
letter-spacing: 1.20000004768372px;
}
.page {
transform: translateY(1080px);
transition: transform 0 linear;
display: none;
opacity: 0;
font-size: 16px;
}
.page.active {
transform: translateY(0px);
transition: all 0.3s ease-out;
display: block;
opacity: 1;
}
#opensource {
color: rgba(0, 0, 0, 0.62);
position: fixed;
margin-top: 50px;
margin-left: 50px;
z-index: 100;
}
#source-modal h4 {
color: black;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fezvrasta.github.io/bootstrap-material-design/dist/css/material-fullpalette.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/FezVrasta/bootstrap-material-design/master/dist/js/ripples.js"></script>
<script type="text/javascript" src="https://rawgit.com/FezVrasta/bootstrap-material-design/master/dist/js/material.js"></script>
<input id="ConfigName" class="form-control floating-label" placeholder="Name" type="text">
<br>
<div class="form-control-wrapper">
<input type="text" class="form-control empty" id="ConfigName1">
<div class="floating-label">floating label</div><span class="material-input"></span>
</div>