简单的 jQuery - 隐藏文本框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8565153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple jQuery - hide text box
提问by dotnetrocks
I am new jQuery, playing around with it. I would like text box when I click button but it doesn't work in that way.
我是新的 jQuery,正在玩它。当我单击按钮时,我想要文本框,但它不起作用。
<input type=text id=txt></input>
<input type=button id=btn value="Click Me"></input>
$document.ready(function() {
$("input#btn").click(function() {
$("input#txt").hide();
});
});
回答by Rafay
$(document).ready(function(){
$("input#btn").click(function(){
$("input#txt").hide();
});
});
missed the ()
around document
you can use the short cut also like
错过了()
周围document
你可以使用捷径也喜欢
$(function(){
//your code here
});
回答by Naftali aka Neal
There is no such thing as $document.ready(
没有这样的事情 $document.ready(
Try doing $(document).ready(
尝试做 $(document).ready(
回答by Spikey21
First of all you have to put "" around your html elements. After that you can fix it like this:
首先,您必须将 "" 放在 html 元素周围。之后,您可以像这样修复它:
<input type="text" id="txt" />
<input type="button" id="btn" value="Click Me" onclick="$('#txt').hide()"/>