jQuery动态输入字段不起作用 [英] jQuery dynamically input fields not working
本文介绍了jQuery动态输入字段不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里遵循了一个教程(对此我做了一些修改):代码
I was following a tutorial (which I modified a bit) here: code
在JSFiddle中,代码运行良好,但是在下面的代码的真实页面上却无法运行,我一直在努力,但是我找不到答案:-(因此可以提供任何帮助.
In JSFiddle the code is working neat, however, on the real page which code is below, is not working, I've been struggling but I cannot find an answer :-( so any help is appreciated.
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="javascript/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function(e) {
$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
});
$('.multi-field .remove-field', $wrapper).click(function() {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});
</script>
<title>AQUATAP - Gestor de Información - Añadir Pedido</title>
</head>
<body>
<form role="form" action="add_order.php" method="POST">
Cliente:
<input type="text" name="cliente" id="buscar">
<br>
<hr />
Fecha de salida:
<br>
<input type="radio" name="salida_pronosticada" value="male">
En el día
<br>
<input type="radio" name="salida_pronosticada" value="male">
2 días
<br>
<input type="radio" name="salida_pronosticada" value="female">
3 días
<br>
<input type="radio" name="salida_pronosticada" value="female">
5 días
<br>
<input type="radio" name="salida_pronosticada" value="female">
1 semana
<br>
<input type="radio" name="salida_pronosticada" value="female">
Otro
<input type="text" name="salida_pronosticada_otro">
días
<br>
<hr />
<label>Stuff y cantidad</label>
<div class="multi-field-wrapper">
<div class="multi-fields">
<div class="multi-field">
<input type="text" class="buscar_prod" name="input_referencia[]">
<input type="text" name="input_cantidad[]">
<button type="button" class="remove-field">
X
</button>
</div>
</div>
<button type="button" class="add-field">
Add field
</button>
<input type="submit" name="guardar" value="Guardar" />
</div>
</form>
</body>
很好...任何帮助,我们感激不尽. 我一直在玩耍,我想我可能会遗漏某些东西……就像脚本未启动一样.
So well... any help is appreciated. I've been playing around and I think i might be missing something... like if the script didn't start.
推荐答案
正如您所说的那样,您的代码正在您展示给我们的页面上运行.
As you are saying that your code is working on the page you showed us.
只需尝试一下:
http://api.jquery.com/ready/
$( document ).ready(function() {
$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function(e) {
$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
});
$('.multi-field .remove-field', $wrapper).click(function() {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});
});
这篇关于jQuery动态输入字段不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文