我遇到了一些与我的代码有关的问题,也许你可以帮忙吗?将ID传递给选择器 - jquery
的Jquery:[更新]
<script>
$(function() {
$(".val_error").dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});
$(".val_open").click(function(event) {
var target = $(this).attr("id");
$('#' + target).dialog('open');
return false;
});
});
</script>
HTML:[更新]
<p class="first_name>
<div class="val_error" id="first_name_err"><?php echo form_error('first_name'); ?></div>
<label for="contact_first_name"><?php echo $label_values->first_name;?></label>
<?php echo form_input('first_name', $form_values->first_name, 'id="first_name"');?>
<button class="val_open" id="first_name">Open</button>
</p>
<p class="last_name">
<div class="val_error" id="last_name_err"><?php echo form_error('last_name'); ?></div>
<label for="contact_last_name"><?php echo $label_values->last_name;?></label>
<?php echo form_input('last_name', $form_values->last_name, 'id="last_name"');?>
<button class="val_open" id="last_name">Open</button>
</p>
所以基本上我试图让该对话框打开刚一次一个ID,而不是一次全部。我试过以下但没有运气:
Jquery的我想会的工作
<script>
$(function() {
$(".val_error"+target).dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});
$(".val_open").click(function(event) {
var target = $this.attr("id");
$(".val_error").dialog("open");
return false;
});
});
</script>
任何帮助/指针,甚至想法将是伟大的!
http://jsfiddle.net/dRRRd/ < - 可以在这里查看
你的HTML是无效的,你不能有相同的ID两个(或更多)的元素。尝试定义和使用数据属性(即数据目标ID) – dievardump 2012-01-29 19:00:08
@DieVarDump我已经排序,现在 – Sean 2012-01-29 19:22:37