正如您從我的代碼中可以看出的那樣。我對此很新,所以請儘量保持您的答案簡單。使用toUpperCase方法使p元素以大寫形式顯示
這個任務是讓我輸入的任何名字都以大寫字母返回。
但我希望一切都以大寫顯示,名稱和段落。我嘗試過所有我能想到的事情,我覺得這很簡單。
這是我到目前爲止有:
$(document).ready(function() {
$("#letter form").submit(function(event) {
var nameInput = $("input#name").val().toUpperCase();
$(".name1").text(nameInput);
$("#response").show();
event.preventDefault();
});
});
#response {
display: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!--link href="css/styles.css" rel="stylesheet" type="text/css"-->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!--script src="js/scripts.js"></script-->
<div class="container">
<h1>Fill in the blanks to write your story!</h1>
<div id="letter">
<form>
<div class="form-group">
<label for="name">A name</label>
<input id="name" class="form-control" type="text">
</div>
<button type="submit" class="btn">Show me the response</button>
</form>
</div>
<div id="response">
<h1>A fantastical adventure</h1>
<blockquote>
<p><span class="name1"></span>, Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</blockquote>
</div>
</div>
當然,剪切和粘貼在這裏唯一的錯誤......但你的jQuery和BootStap外部'script'電話是相反的。在Bootstrap之前放置jQuery。 –
[在javascript中將小寫字母轉換爲大寫]可能的副本(https://stackoverflow.com/questions/2354716/convert-lowercase-letter-to-upper-case-in-javascript) – TalkLittle
是的,這是一個複製和粘貼錯誤。儘管謝謝! – rainbowpudding