【发布时间】:2012-01-29 18:51:45
【问题描述】:
我的代码有一些问题,也许你能帮忙?
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>
任何帮助/指针甚至想法都会很棒!
【问题讨论】:
-
您的 html 无效,您不能有两个(或更多)具有相同 id 的元素。尝试定义和使用 data- 属性(即 data-target-id )
-
@DieVarDump 我已经整理好了
标签: javascript jquery variables selector