【问题标题】:call external common function in jquery ui modal在jquery ui modal中调用外部常用函数
【发布时间】:2018-04-14 00:59:11
【问题描述】:

我有一个调用外部 JSP 的 jQuery UI 模式。在 JSP 中,我也有 HTML 和 jQuery 代码。打开模式时,会出现一个搜索屏幕,单击时搜索按钮应计算文本框中的字符数。

除了找不到模态加载的输入框外,它会找到父窗口的元素(也是搜索屏幕)。

$(document).ready(function()
{  
    console.log('ready!');
    // Just some test code
    $("input[type='text']").each(function()
    {
        console.log("textbox: " + $(this).attr("id"));
    });
});

function countSearchChars()
{
    var count = 0;

    $("input[type='text'][name^='SEARCH_' i]").each(function()
    {
        alert($(this).attr("id") + " val count: " + $(this).val().length);
        count += $(this).val().length;
    });
    return count;
}

父 JSP 调用 -

$("body").append("<div id='modalCustomerServiceWindow'></div>");
$("#modalCustomerServiceWindow").dialog(
{ 
    autoOpen: false, draggable: true, 
    resizable: true, height: heightScreen, width: widthScreen, 
    modal: true, title: "Customer Service Notes",
    closeOnEscape: true,
    open: function(event, ui)
    {
        $(this).load(url);
    }
});
$("#modalCustomerServiceWindow").dialog("open");

返回 -

文本框:SEARCH_name_last 文本框:SEARCH_name_first 文本框:SEARCH_comp_1 文本框:SEARCH_internet_address 文本框:SEARCH_reg_uid 文本框:SEARCH_show_code 文本框:SEARCH_mail_type_code 文本框:SEARCH_org_id 文本框:SEARCH_link_reg_uid

没有找到这些 -

<input type="textbox" class="search-field comment" name="search_comments" 
            id="search_comments" size="90">
<input type="textbox" class="search-field" name="search_add_date" 
            id="search_add_date" size="15"></TH>
<input type="textbox" class="search-field" name="search_add_userid" 
            id="search_add_userid" size="9">

我将count characters方法放在全局js文件中并将其移至JSP文件中,结果相同。我将脚本标签移到正文标签之前,但没有任何不同。

【问题讨论】:

    标签: javascript jquery jquery-ui-dialog


    【解决方案1】:

    我能够找出错误。这段代码从 2000 年就已经存在了。

    <input type="textbox">
    

    我猜 IE 显示这个没有问题,但 jQuery 显然找不到它。

    【讨论】:

      猜你喜欢
      • 2016-01-03
      • 2012-11-28
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 2011-08-18
      • 1970-01-01
      相关资源
      最近更新 更多