如何将类添加到仅在单击事件上出现的表单标记?
如何将类添加到仅在单击事件上出现的表单标记? 例如:我确实有这个...
<p>Below is a form: <span>show form</span></p>
<div class="container"></div>
当用户单击“显示表单”时,jQuery 将在“容器”类中添加一个新表单
<p>Below is a form:</p>
<div class="container">
<form>
<-- some code here -->
</form>
</div>
注意:该表单仍然在首页加载时不存在< /强>。仅当用户单击范围时它才会显示。有没有一种方法可以让 jQuery 在表单显示后加载?
这就是我计划在 jQuery 上实现的方法,但是它不起作用,请更正这个...
$("span").click(function(){
$(".container form").ready(function(){
$(this).addClass("active");
})
})
谢谢。
How to add a class to a form tag that only present on click event?
For example: I do have this...
<p>Below is a form: <span>show form</span></p>
<div class="container"></div>
when user clicks the "show form", jQuery will add a new form inside the class "container"
<p>Below is a form:</p>
<div class="container">
<form>
<-- some code here -->
</form>
</div>
note: The form still does not exist on first page load. It will only shows up when a user clicks on the span. Is there a way wherein the jQuery will just load after the form shows up?
This is how I plan to make it on jQuery, but it don't work, please correct this...
$("span").click(function(){
$(".container form").ready(function(){
$(this).addClass("active");
})
})
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您可能想利用 .live jQuery 事件。这允许您将事件附加到 DOM 加载后创建的元素。例如,当您通过 AJAX 加载其他元素时。在这个简单的示例中,您单击“单击我”。表单是动态加载的,并被赋予活动类。
http://jsfiddle.net/v5j42/1/
I think that you might want to make use of the .live jQuery event. This allows you to attach events to elements created after the DOM has loaded. For instance when you load additional elements via AJAX. In this simple example you click on 'click me.' A form is dynamically loaded and it is given the active class.
http://jsfiddle.net/v5j42/1/
怎么样
这会在单击时将所需的 CSS 类添加到您的表单按钮 ID 中。
How about
This will add the desired CSS class to your form button ID when clicked.
document.ready 超出了绑定代码:
document.ready goes outside of the binding code:
你可以这样做......不确认但应该解决你的问题。
尝试检查 DOM 中是否存在表单 id..像这样..
希望这对您有帮助...
you can do it in this way..not confirm but should solve your problem.
try to check form id exist in DOM or not..like this..
hope this helps you...
我想您可能正在寻找像这样简单的东西?
HTML
jQuery
http://jsfiddle.net/jasongennaro/9YNLP/1/
I think you might be looking for something as simple as this?
HTML
jQuery
http://jsfiddle.net/jasongennaro/9YNLP/1/