可能很容易。当我点击我创建的表单中的提交按钮时,我应该在我的控制台上看到“点击”消息,但它不会出现。任何想法为什么会这样?
$("#button").on("click", function() {
console.log("clicked");
return false;
});
<div class="col-md-8">
<form>
<div class="form-group">
<label for="name" class="sr-only">Name</label>
<input type="text" class="form-control" id="name" placeholder="Your name here" maxlength="20">
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="email" class="form-control" id="email" placeholder="Your email here*" required="required">
</div>
<label for="textBox" class="sr-only">TextBox</label>
<textarea class="form-control message-box" id="textBox" style="resize:none" cols="40" rows="5" placeholder="Your message here" minlength="20"></textarea>
<button type="submit" class="btn btn-default" id="button">Submit</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
答案 0 :(得分:0)
$
函数仅由jQuery定义。你需要包含jQuery才能工作。
$("#button").on("click", function() {
console.log("clicked");
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-8">
<form>
<div class="form-group">
<label for="name" class="sr-only">Name</label>
<input type="text" class="form-control" id="name" placeholder="Your name here" maxlength="20">
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="email" class="form-control" id="email" placeholder="Your email here*" required="required">
</div>
<label for="textBox" class="sr-only">TextBox</label>
<textarea class="form-control message-box" id="textBox" style="resize:none" cols="40" rows="5" placeholder="Your message here" minlength="20"></textarea>
<button type="submit" class="btn btn-default" id="button">Submit</button>
</form>
添加jQuery在这里工作。