我遇到了一些與我的代碼有關的問題,也許你可以幫忙嗎?將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