如何为jquery UI对话框添加标题?

时间:2012-10-09 09:57:02

标签: javascript jquery jquery-ui

如何为此案例title添加JqueryUI dialog box。此dialog框将根据ruby on rails中的model名称打开。

html页面示例:

<%= link_to pro_generic_lookup_data_path("Enr::Rds::Section2009", format: :js), data: {remote: true} %>

此处,pro_generic_lookup_data可以选择uidialog box.因此,它会打开取决于model name("Enr::Rds::Section2009")

的JavaScript

var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) {
  var section_value = $(".cross-reference-section-value");
  var section_id = $(".cross-reference-section-value-id");
  var section_clear_img = $(".cross-reference-section-clear-img");
  section_id.val(id);
  section_value.text(to_s);
  section_value.css('display', 'inline');
  section_clear_img.css('display', 'inline');
  $(section_clear_img).on('click', function() {
    section_value.text('')
    section_id.val('')
    section_clear_img.css('display', 'none');
  });
  var question_link = $('#question_picker').attr('href');
  question_link = question_link.replace(/\?+$/, '');
  question_link = question_link + '?columns[enr_rds_section_id]=' + id;
  $('#question_picker').attr('href', question_link);
  $("#modal_popup").dialog("destroy");      
};

我有三个相同的字段。所以,我需要为这三个领域分别提供标题。谢谢!

1 个答案:

答案 0 :(得分:2)

除了一些基本格式和适用的链式选择器之外,代码还可以。

var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) {
    var $section_value = $(".cross-reference-section-value");
    var $section_id = $(".cross-reference-section-value-id");
    var $section_clear_img = $(".cross-reference-section-clear-img");

    $section_id.val(id);    
    $section_value.text(to_s).css('display', 'inline');

    $section_clear_img.css('display', 'inline').on('click', function() {
        $section_value.text('')
        $section_id.val('')
        $section_clear_img.css('display', 'none');
    });

    var question_link = $('#question_picker').attr('href');
    question_link = question_link.replace(/\?+$/, '');
    question_link = question_link + '?columns[enr_rds_section_id]=' + id;
    $('#question_picker').prop('href', question_link);

    $("#modal_popup").dialog("destroy");      
};