[英]JQuery Mobile hide <input> does not hide the surrounding <div> of the <input> field
當我在JQuery Mobile中使用hide()
函數隱藏<input>
標記時,它也隱藏了<input>
它不會隱藏由JQuery Mobile實現的<input>
周圍的<input>
<div>
。
我之后可以使用DOM來使它消失,但我正在尋找更好的解決方案。
在這種情況下,您會注意到<input type="text" name="lastname" id="lastname">
周圍的div仍在屏幕上(您可以像這里一樣運行W3C編輯器 ):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Text Inputs</h1>
</div>
<div data-role="main" class="ui-content">
<form method="post" action="/action_page_post.php">
<div class="ui-field-contain">
<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname">
<label for="lastname">Last name:</label>
<input type="text" name="lastname" id="lastname">
<script type="text/javascript">
$(document).ready(
$('body').find('[id="lastname"]').hide()
);
</script>
</div>
<input type="submit" data-inline="true" value="Submit">
</form>
</div>
</div>
</body>
</html>
我已經嘗試在parent()
上應用hide()
函數,但它確實將父對象視為,我要隱藏的<div>
尚未出現在屏幕上,並隱藏整個表單而不是特定的領域:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Text Inputs</h1>
</div>
<div data-role="main" class="ui-content">
<form method="post" action="/action_page_post.php">
<div class="ui-field-contain">
<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname">
<label for="lastname">Last name:</label>
<input type="text" name="lastname" id="lastname">
<script type="text/javascript">
$(document).ready(
$('body').find('[id="lastname"]').parent().hide()
);
</script>
</div>
<input type="submit" data-inline="true" value="Submit">
</form>
</div>
</div>
</body>
</html>
在您嘗試訪問父div時,它不會被繪制..一種方法是使用JavaScript setTimeout()方法隱藏該div元素:
setTimeout(function() { $('#lastname').parent().hide(); }, 1);
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <div data-role="page"> <div data-role="header"> <h1>Text Inputs</h1> </div> <div data-role="main" class="ui-content"> <form method="post" action="/action_page_post.php"> <div class="ui-field-contain"> <label for="firstname">First name:</label> <input type="text" name="firstname" id="firstname"> <label for="lastname">Last name:</label> <input type="text" name="lastname" id="lastname"> </div> <input type="submit" data-inline="true" value="Submit"> </form> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.