是否可以访问其他功能中的克隆
Is it possible to access clones in other functions?
我有一个名为taskButtonClick()的函数,它:
- 将变量形式设置为克隆。
- 将变量 formParent 设置为最外层的div。
- 删除父div 及其元素。
-
并将这些已删除的元素替换为表单。
function taskButtonClick() { $(".task-btn").click(function(){ // Setting form to the clone I want to acces in .on() var form = $(this).closest('#form-to-date').clone(true); var formParent = $(this).closest('#date-container'); $(this).closest('#form-to-date').remove(); $(formParent).html('' <form>' <fieldset>' <legend>Task<button class="btn task-btn" id="exit- button"><img src="http://localhost/ia/assets/img/remove.png"></button></legend>' <input type="text" class="span12 input-xlarge" id="input01">' <div class="control-group">' <div class="controls">' </div>' </div>' <div class="form-actions">' <button class="btn btn-primary span12" type="submit">Save changes</button>' </div>' </fieldset>' </form>' '); }); }
中添加了一个退出按钮,我为其创建了一个 .on() 函数并附加了一个单击处理程序。我正在尝试找出一种方法来从 .on 函数中访问变量表单(克隆)并将表单替换为之前的内容:
$("#date-container").on("click", "#exit-button", function(event){
alert("Exit Button Works.");
event.preventDefault();
// Here's kind of what I'm going for
$(form).appendTo(formParent);
});
我对jquery不是很熟悉,所以如果我能以某种方式更好地澄清,请告诉我。
Edit: Here's where I'm calling the funcitons:
$('document').ready(function(){
setAjax();
initialize();
setDates();
setButton();
setActiveNav();
taskButtonClick();
removeButtonClicked();
});
尝试声明一个全局变量。
$(document).ready(function(){
//Notice variable is outside of the event function. It can be accessed by other functions and events.
var formParent = null;
$(".task-btn").click(function(){
// Setting form to the clone I want to acces in .on()
var form = $(this).closest('#form-to-date').clone(true);
formParent = $(this).closest('#date-container');
$(this).closest('#form-to-date').remove();
$(formParent).html(''
<form>'
<fieldset>'
<legend>Task<button class="btn task-btn" id="exit- button"><img src="http://localhost/ia/assets/img/remove.png"></button></legend>'
<input type="text" class="span12 input-xlarge" id="input01">'
<div class="control-group">'
<div class="controls">'
</div>'
</div>'
<div class="form-actions">'
<button class="btn btn-primary span12" type="submit">Save changes</button>'
</div>'
</fieldset>'
</form>'
');
});
});
如果要
使用克隆变量,请使用全局变量声明。
相关文章:
- 除修剪外的其他功能
- 计时器在使用 jQuery 一分钟后没有触发,或者每 1 分钟后给出一些其他解决方案来触发功能
- jQuery插件与其他基本的显示/隐藏功能冲突
- 淡入、滑入和其他需要显示的功能:无无法正常工作
- 是否可以访问其他功能中的克隆
- Jquery停止在其他开关外壳内的开关盒上的更改功能
- 使用其他点击功能重新加载
- 多功能 javascript 停止其他如果警报取消
- 解释$apply和$eval |我可以用其他功能替换它们吗 |AngularJS.
- 如何根据茉莉花单元测试中的其他对象测试功能
- 创建范围功能在除IE以外的其他浏览器中不起作用
- 是否可以访问同一文件中的其他模块导出功能
- 向 Google Maps API 添加其他功能
- 我是否可以在 Bootstrap 3 中为折叠手风琴指定一个相对的“数据目标”,同时保留“折叠其他”功能
- document.ready在同一页上禁用其他功能
- 单击功能时取消选中其他单选按钮
- 如果中途发生其他事件,如何重置clickToggle功能
- 获取将图像调整为其容器大小的脚本的名称+其他功能
- 如何实现像YouTube/其他网站这样的页面功能
- 单击其他元素时重置功能