单击后隐藏和显示两个按钮
hide and show two buttons after clicked on it
请给我一个基于下面我的按钮的例子不使用 onclick 函数:
<button id="button1">Example 1</button>
<button id="button2" style='display:none;'>Example 2</button>
例如:
Button1 is default, after clicked on it will hide and button2 will be
appeared and after click on button2 again will hide and button1 will
be appeared.
我需要一个 jQuery 来实现这个,只有 ID,没有 onclick 功能。
是否可以获取隐藏和显示按钮的 ID?
提前致谢
你可以使用 not()
做一些简单的事情,但如果没有点击事件处理程序你也做不到
var btn = $('#button1,#button2').click(function() { // bind click handler to both button
$(this).hide(); // hide the clicked button
btn.not(this).show(); // show the another button which is hidden
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="button1">Example 1</button>
<button id="button2" style='display:none;'>Example 2</button>
请给我一个基于下面我的按钮的例子不使用 onclick 函数:
<button id="button1">Example 1</button>
<button id="button2" style='display:none;'>Example 2</button>
例如:
Button1 is default, after clicked on it will hide and button2 will be appeared and after click on button2 again will hide and button1 will be appeared.
我需要一个 jQuery 来实现这个,只有 ID,没有 onclick 功能。
是否可以获取隐藏和显示按钮的 ID?
提前致谢
你可以使用 not()
做一些简单的事情,但如果没有点击事件处理程序你也做不到
var btn = $('#button1,#button2').click(function() { // bind click handler to both button
$(this).hide(); // hide the clicked button
btn.not(this).show(); // show the another button which is hidden
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="button1">Example 1</button>
<button id="button2" style='display:none;'>Example 2</button>