【问题标题】:Setting On Change on id from parameter does not work从参数设置更改 id 不起作用
【发布时间】:2015-04-28 15:40:30
【问题描述】:

我使用的是 SharePoint 2013,但这更像是一个 jQuery 问题/问题。 在 SharePoint 中,表单元素根据名称和某种键被赋予 ID。

我能够获取我尝试添加“on change”功能的表单元素的 ID。

var idEventDate = $('nobr:contains("Event Date")').closest('tr').find('input[title$="Event Date"]').prop('id');

我使用警报来确保我得到了价值。

当我采用该值并创建“on change”侦听器时,什么也没有发生。也没有任何错误。

在下面的代码中,我正在插入一个 div,然后我尝试将“on change”函数添加到 Event Date 字段元素。

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push( "sharePointReady" );

function sharePointReady() {
    // Adding a Title as a quick way to determine which screen I am on
    $('nobr:contains("Title")').closest('table').before('<div id="customHeader"><h1>Create a New Memo</h1></div>');

    var idEventDate = $('nobr:contains("Event Date")').closest('tr').find('input[title$="Event Date"]').prop('id');

    $(document).on("change","#" + idEventDate, function(){
        alert("changed");
    });
}

【问题讨论】:

    标签: jquery forms sharepoint element onchange


    【解决方案1】:

    我发现没有必要获取 ID,因为我已经找到了元素。

    $('nobr:contains("Event Date")').closest('tr').find('input[title$="Event Date"]').on("change",  function(){
            alert("changed");
        });
    

    但是,我仍然希望将 ID 作为字符串获取。但是,就目前而言,这只是一个额外的不需要的步骤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      相关资源
      最近更新 更多